s-KaiNet / spfx-check-locale

Check the consistency of your localization files inside SharePoint Framework projects.

Home Page:https://marketplace.visualstudio.com/items?itemName=s-kainet.spfx-check-locale

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Checks that your localization files match the schema inside mystrings.d.ts

npm version

spfx-check-locale is a Node.js module which allows you to check the consistency of your localization files inside SharePoint Framework projects, i.e. localization files match the schema inside mystrings.d.ts.

Also available as a VSCode extension to support nice real-time error reporting.

How to use

Install

npm install spfx-check-locale --save-dev

Update gulpfile.js

const checkLocales = require('spfx-check-locale').checkForErrors;

const argv = build.rig.getYargs().argv;
if (argv.production) {
  const check = build.subTask('check-locales', function (gulp, buildOptions, done) {
    checkLocales({
      projectPath: buildOptions.rootPath,
      printErrors: true
    })
      .then(result => {
        if (result.diagnosticData.length === 0) {
          done();
        } else {
          done('Found errors in localization files');
        }
      }).catch(done);
  });

  build.rig.addPostBuildTask(build.task('check-locales', check));
}

Now every time you build your SPFx solution for the production spfx-check-locale will check the consistency of all localization files, will print errors report and will fail a build if there are any errors.

Why on production build only? Because the checking takes from 1 to 3 seconds, thus no reason to make your serve process slower. Also, with VSCode extension you have nice real-time error highlights without hurting performance.

API

checkForErrors(options)

Asynchronously checks your SPFx project for inconsistencies in localization files

params

  • options - required, options object with below properties:
    • projectPath - required string, an absolute path to your SPFx solution
    • printErrors - optional boolean, whether to print errors in console

returns

A promise, which resolves to a CheckResults object

About

Check the consistency of your localization files inside SharePoint Framework projects.

https://marketplace.visualstudio.com/items?itemName=s-kainet.spfx-check-locale

License:MIT License


Languages

Language:TypeScript 94.1%Language:JavaScript 5.7%Language:SCSS 0.2%