Check the consistency of your localization files inside SharePoint Framework projects.
mystrings.d.ts
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.
npm install spfx-check-locale --save-dev
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.
Asynchronously checks your SPFx project for inconsistencies in localization files
options
- required, options object with below properties:projectPath
- required string, an absolute path to your SPFx solutionprintErrors
- optional boolean, whether to print errors in consoleA promise, which resolves to a CheckResults
object