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

Language files. #84

Merged
merged 7 commits into from May 29, 2018
Adjustment to prevent unnecessary writes.
  • Loading branch information
zarembsky committed May 28, 2018
commit a8acf64597c89a00333131ae1377d290e2832c68
@@ -96,25 +96,30 @@ function validateJson(paths) {
}

/**
* Checks for missing placeholders in all the locale files. Add them from English file
* Checks for missing placeholders in all the locale files. Copy them over from English file
* @params array paths An array of strings denoting the paths to all the locale files
* @const string DEFAULT_LOCALE_PATH The location of the default locale JSON file
* @return Promise Resolves if no extra tokens were found,
* @return Promise Always call resolve (no error handling)
*/
function fixMissingPlaceholders(paths) {
return new Promise((resolve, reject) => {
let defaultLocaleJson = require(DEFAULT_LOCALE_PATH);
paths.forEach(path => {
if(path !== DEFAULT_LOCALE_PATH) {
let dirty = false;
let localeJson = require('.' + path);
Object.keys(defaultLocaleJson).forEach(key => {
if (defaultLocaleJson[key].hasOwnProperty('placeholders')) {
if (localeJson[key] && !localeJson[key].hasOwnProperty('placeholders')) {
dirty = true;
localeJson[key].placeholders = defaultLocaleJson[key].placeholders;
}
}
});
fs.writeFileSync(path, JSON.stringify(localeJson, null, '\t'));
if(dirty) {
console.log(`Placeholders were added to ${path}`);
fs.writeFileSync(path, JSON.stringify(localeJson, null, '\t'));
}
}
});
resolve();
ProTip! Use n and p to navigate between commits in a pull request.