diff --git a/frontend/package.json b/frontend/package.json index 1733b9b14..4a3cb9c83 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -56,6 +56,7 @@ "eslint-plugin-svelte": "^2.39.0", "globals": "^13.24.0", "graphql": "^16.8.1", + "json5": "^2.2.3", "jwt-decode": "^4.0.0", "postcss": "^8.4.38", "rimraf": "^5.0.7", diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml index 1fed2c423..1fd0c235b 100644 --- a/frontend/pnpm-lock.yaml +++ b/frontend/pnpm-lock.yaml @@ -168,6 +168,9 @@ importers: graphql: specifier: ^16.8.1 version: 16.8.1 + json5: + specifier: ^2.2.3 + version: 2.2.3 jwt-decode: specifier: ^4.0.0 version: 4.0.0 diff --git a/frontend/src/lib/i18n/locales/update_tracker.mjs b/frontend/src/lib/i18n/locales/update_tracker.mjs new file mode 100644 index 000000000..1e8d3c225 --- /dev/null +++ b/frontend/src/lib/i18n/locales/update_tracker.mjs @@ -0,0 +1,45 @@ +import * as fs from 'fs'; +import * as path from 'path'; +import json5 from 'json5'; + +function compileKeys(obj, prefix = '') { + let keys = []; + for (const key in obj) { + const fullKey = prefix ? `${prefix}.${key}` : key; + keys.push(fullKey); + const subKey = obj[key]; + if (typeof subKey !== 'string') { + const subKeys = compileKeys(subKey, fullKey); + keys = keys.concat(subKeys); + } + } + return keys; +} + +function getDiffKeys(stdKeys, lang) { + const langJson = json5.parse(fs.readFileSync(`${lang}.json`, 'utf-8')); + const langKeysSet = new Set(compileKeys(langJson, '')); + const diff = stdKeys.filter(x => !langKeysSet.has(x)); + return diff; +} + +function main() { + const dirname = import.meta.dirname; + const files = fs.readdirSync(dirname); + const locales = files + .filter(file => path.extname(file).toLowerCase() === '.json') + .map(file => path.basename(file, '.json')) + .filter(file => file !== 'en'); + + const enJson = json5.parse(fs.readFileSync('en.json', 'utf-8')); + const enAllKeys = compileKeys(enJson, ''); + + const output = {}; + locales.forEach(lang => { + const diff = getDiffKeys(enAllKeys, lang); + output[lang] = diff; + }); + console.log(output); +} + +main();