Updating i18n:scrub script to remove defined keys from missing namespace

This commit is contained in:
Jeff Avallone 2018-05-31 18:23:04 -04:00
parent b575b9a0cc
commit 479d035cd0

View File

@ -53,7 +53,7 @@ loadLocales()
languages.forEach(langName => {
const lang = locales[langName];
const presentKeys = Object.keys(lang).reduce((list, nsName) => {
const presentKeys = Object.keys(lang).filter(nsName => nsName !== 'missing').reduce((list, nsName) => {
return list.concat(Object.keys(lang[nsName]));
}, []);
const missingKeys = requiredKeys.filter(key => !presentKeys.includes(key));
@ -68,10 +68,23 @@ loadLocales()
}
missingKeys.forEach(key => {
console.log(colors.yellow.bold('MISSING:'), `${ langName } need values for "${ colors.bold(key) }".`); //eslint-disable-line no-console
if (lang.missing[key]) {
return;
}
console.log(colors.yellow.bold('MISSING:'), `${ langName } needs value for "${ colors.bold(key) }".`); //eslint-disable-line no-console
lang.missing[key] = sourceLocale[key];
});
presentKeys.forEach(key => {
if (!lang.missing[key]) {
return;
}
console.log(colors.yellow.bold('DEFINED:'), `Removing "${ colors.bold(key) }" from ${ langName}.missing. It is defined elsewhere.`); // eslint-disable-line no-console
delete lang.missing[key];
});
extraKeys.forEach(key => {
console.log(colors.yellow.bold('EXTRA:'), `${ langName } has extra key for "${ colors.bold(key) }". It should be removed.`); // eslint-disable-line no-console
});