From 83a093e36be69f2eb82b95396b290788077d766b Mon Sep 17 00:00:00 2001 From: J Francisco Rader Date: Mon, 1 Mar 2021 11:18:01 -0500 Subject: [PATCH] Add script for getting missing keys --- phone/i18n.missingKeys.js | 77 +++++++++++++++++++++++++++++++++++++++ phone/package.json | 1 + 2 files changed, 78 insertions(+) create mode 100644 phone/i18n.missingKeys.js diff --git a/phone/i18n.missingKeys.js b/phone/i18n.missingKeys.js new file mode 100644 index 0000000..7beedb2 --- /dev/null +++ b/phone/i18n.missingKeys.js @@ -0,0 +1,77 @@ +const args = process.argv.slice(2); + +console.log(args); + +const path = './src/locale/'; + +const langs = ['bh', 'es', 'fr', 'pt', 'ptbr', 'sv', 'tr']; + +const defaultLang = 'en'; + +const langFiles = []; + +let defaultLangFile; + +const missingKeys = {}; + +const promises = langs + .filter((l) => (args[0] ? args[0] === l : true)) + .map((l) => { + return new Promise((res, rej) => { + import(path + l + '.json') + .then((module) => { + langFiles.push(module.default.translation); + res(); + }) + .catch((e) => { + console.error(e); + rej(e); + }); + }); + }); + +const Load = () => Promise.all(promises); + +const LoadDefault = () => + new Promise((res, rej) => { + import(path + defaultLang + '.json') + .then((module) => { + defaultLangFile = module.default.translation; + res(); + }) + .catch((e) => { + console.error(e); + rej(e); + }); + }); + +(async () => { + const filteredLangs = langs.filter((l) => (args[0] ? args[0] === l : true)); + + await LoadDefault(); + await Load(); + let idx = 0; + for (const file of langFiles) { + const currLang = filteredLangs[idx]; + if (currLang === defaultLang) { + return; + } + idx++; + if (args[0] && args[0] !== currLang) { + return; + } + missingKeys[currLang] = []; + for (const dKey in defaultLangFile) { + let exists = false; + for (const key in file) { + if (key === dKey) { + exists = true; + } + } + if (!exists) { + missingKeys[currLang].push([dKey, defaultLangFile[dKey]]); + } + } + } + console.log(missingKeys); +})(); diff --git a/phone/package.json b/phone/package.json index 7c6dc67..7e0a0c3 100644 --- a/phone/package.json +++ b/phone/package.json @@ -78,6 +78,7 @@ "webpack-cli": "^3.3.12" }, "scripts": { + "i18n:missing": "node --experimental-json-modules i18n.missingKeys.js", "copy:config": "cp-cli ../config.json ./src/config.autogen.json", "start": "yarn copy:config && react-scripts start", "watch": "cra-build-watch --disable-chunks --build-path ../resources/html --output-filename dev.js",