From cbfb5a0ba23eb2871fabb32e6a20c0bd2ba11611 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Sun, 20 Aug 2023 14:07:50 +0200 Subject: [PATCH] Update localization sync --- scripts/sync-localization.js | 39 +++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/scripts/sync-localization.js b/scripts/sync-localization.js index 033f5682..c915f8e0 100644 --- a/scripts/sync-localization.js +++ b/scripts/sync-localization.js @@ -1,5 +1,6 @@ const fs = require('fs'); const path = require('path'); +const glob = require('glob'); (async () => { // Get all the files from the l10n directory @@ -17,7 +18,13 @@ const path = require('path'); // Get the file content const fileContent = fs.readFileSync(path.join(__dirname, `../l10n/${file}`), 'utf8'); - const content = JSON.parse(fileContent); + let content = {}; + + try { + content = JSON.parse(fileContent); + } catch (e) { + // Ignore the error + } // Loop through the EN keys for (const key of enKeys) { @@ -30,4 +37,34 @@ const path = require('path'); // Write the file fs.writeFileSync(path.join(__dirname, `../l10n/${file}`), JSON.stringify(content, null, 2), 'utf8'); } + + + // Package JSON + const enPkgFile = fs.readFileSync(path.join(__dirname, '../package.nls.json'), 'utf8'); + const enPkgContent = JSON.parse(enPkgFile); + const enPkgKeys = Object.keys(enPkgContent); + + const pkgFiles = glob.sync(path.join(__dirname, '../package.nls.*.json')); + + for (const file of pkgFiles) { + const fileContent = fs.readFileSync(file, 'utf8'); + let content = {}; + + try { + content = JSON.parse(fileContent); + } catch (e) { + // Ignore the error + } + + // Loop through the EN keys + for (const key of enPkgKeys) { + // If the key does not exist in the file, add it + if (!content[key]) { + content[key] = `🚧: ${enPkgContent[key]}`; + } + } + + // Write the file + fs.writeFileSync(file, JSON.stringify(content, null, 2), 'utf8'); + } })(); \ No newline at end of file