Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check i18n file for missing variables #18762

Merged
merged 10 commits into from
Sep 21, 2020
Prev Previous commit
Next Next commit
Fix status code
sampaiodiego committed Sep 18, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit d524db145095d9c3c6bfc868cc788b05ac21621e
29 changes: 26 additions & 3 deletions .scripts/check-i18n.js
Original file line number Diff line number Diff line change
@@ -34,9 +34,32 @@ const checkFiles = async (path, source) => {

const i18nFiles = await fg([`${ path }/**/*.i18n.json`]);

let totalErrors = 0;
// const getInvalidKeys = (json) =>
// usedKeys
// .filter(({ key }) => typeof json[key] !== 'undefined')
// .filter(({ key, replaces }) => {
// const miss = replaces.filter((replace) => json[key].indexOf(replace) === -1);

// return miss.length > 0;
// })
// .map(({ key }) => key);

// const removeMissingKeys = () => {
// const allKeys = Object.keys(sourceFile);
// i18nFiles.forEach((file) => {
// const json = JSON.parse(fs.readFileSync(file, 'utf8'));

// const invalidKeys = getInvalidKeys(json);

const result = i18nFiles.filter((file) => {
// const validKeys = allKeys.filter((key) => !invalidKeys.includes(key));
// // console.log('validKeys', file, validKeys);

// fs.writeFileSync(file, JSON.stringify(json, validKeys, 2));
// });
// };

let totalErrors = 0;
i18nFiles.filter((file) => {
const json = JSON.parse(fs.readFileSync(file, 'utf8'));

const result = validateKeys(json);
@@ -56,7 +79,7 @@ const checkFiles = async (path, source) => {
return false;
});

if (result.length > 0) {
if (totalErrors > 0) {
console.error(`\n${ totalErrors } errors found`);
process.exit(1);
}