From da555fd3e37839f2aa71231606d3df2d402d2283 Mon Sep 17 00:00:00 2001 From: tuliomir Date: Fri, 28 Mar 2025 17:50:33 -0300 Subject: [PATCH 1/5] feat: strict languages on check_i18n --- scripts/update_translations.js | 44 +++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/scripts/update_translations.js b/scripts/update_translations.js index da3fabd26..c9892d284 100644 --- a/scripts/update_translations.js +++ b/scripts/update_translations.js @@ -30,7 +30,18 @@ const { tmpdir } = require('node:os'); * - Lastly, checking for filesystem changes using `git status` for easier debugging, if needed */ +/** + * All translations that should exist in the `locale` folder. Some of those may be incomplete. + * @type {string[]} + */ const existingTranslations = ['pt-br', 'da', 'ru-ru']; +/** + * Translations that are mandatory to be complete. If any of those language files contain missing + * lines, the CI validation script will fail. + * Can be overridden by the `--strict-languages` argument. + * @type {string[]} + */ +const mandatoryTranslations = ['pt-br']; const temporaryDirs = []; /** @@ -107,10 +118,10 @@ function mergeTranslations() { /** * Checks if all `.po` files have all messages from the `.pot` file. * Allows untranslated messages if `strict` is false. - * @param {boolean} strict - If true, does not allow untranslated messages. - * @returns {boolean} True if an error happened or if there are any differences + * @param {string[]} strictLanguages - Does not allow untranslated messages for those languages. + * @returns {boolean} True if an error happened or if there are any missing i18n lines */ -function checkPoTranslations(strict = false) { +function checkPoTranslations(strictLanguages) { console.log(`⏳ Checking translations...`); const localeDir = 'locale'; @@ -121,7 +132,10 @@ function checkPoTranslations(strict = false) { subfolders.forEach((subfolder) => { const poFile = path.join(localeDir, subfolder, 'texts.po'); - const cmd = strict ? `msgcmp ${poFile} ${potFile}` : `msgcmp --use-untranslated ${poFile} ${potFile}`; + const isStrictLanguage = strictLanguages.includes(subfolder); + const cmd = isStrictLanguage + ? `msgcmp ${poFile} ${potFile}` + : `msgcmp --use-untranslated ${poFile} ${potFile}`; try { // If there are any differences, the command will throw an error execSync(cmd, { stdio: 'inherit' }); @@ -227,8 +241,26 @@ process.on('exit', (code) => { }); }); +/** + * Parses the command line arguments and returns an object with the parameters + * @returns {{isCiValidationRun: boolean, strictLanguages: string[]}} + */ +function getCliParameters() { + const args = process.argv.slice(2); + const parameters = {}; + args.forEach((arg) => { + const [key, value] = arg.split('='); + parameters[key.replace('--', '')] = value || true; + }); + + return { + isCiValidationRun: parameters['ci-validation'] || false, + strictLanguages: parameters['strict-languages']?.split(',') || mandatoryTranslations, + } +} + try { - const isCiValidationRun = process.argv.includes('--ci-validation'); + const { isCiValidationRun, strictLanguages } = getCliParameters(); runLocaleUpdatePot(); mergeTranslations(); @@ -243,7 +275,7 @@ try { // If this script was called with the "--ci-validation" argument, it will fail if there are any // fuzzy tags that need reviewing const invalidPot = checkPotOutdated(); - const invalidPos = checkPoTranslations(); + const invalidPos = checkPoTranslations(strictLanguages); checkForChanges(); // This will print the diff if changes are found, but not fail the script if (invalidPot || invalidPos || hasFuzzyTags) { console.log(`❌ Translations are not up-to-date. Please review the changes.`); From 471b2df9718b25ff09b610cf787edee09fa90ffc Mon Sep 17 00:00:00 2001 From: tuliomir Date: Fri, 28 Mar 2025 17:54:50 -0300 Subject: [PATCH 2/5] chore: missing pt-br translations --- locale/pt-br/texts.po | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/locale/pt-br/texts.po b/locale/pt-br/texts.po index fcc4a2147..1e92c79ed 100644 --- a/locale/pt-br/texts.po +++ b/locale/pt-br/texts.po @@ -961,7 +961,7 @@ msgstr "Digitar" #: src/screens/Reown/ReownManual.js:45 msgid "Reown URI" -msgstr "" +msgstr "URI do Reown" #: src/screens/Reown/ReownManual.js:57 src/screens/Reown/ReownScan.js:34 msgid "Connect" @@ -1038,19 +1038,19 @@ msgstr "" #: src/screens/NetworkSettings/CustomNetworkSettingsScreen.js:232 msgid "Node URL" -msgstr "" +msgstr "URL do Fullnode" #: src/screens/NetworkSettings/CustomNetworkSettingsScreen.js:242 msgid "Explorer URL" -msgstr "" +msgstr "URL do Explorer" #: src/screens/NetworkSettings/CustomNetworkSettingsScreen.js:251 msgid "Explorer Service URL" -msgstr "" +msgstr "URL do Explorer Service" #: src/screens/NetworkSettings/CustomNetworkSettingsScreen.js:260 msgid "Transaction Mining Service URL" -msgstr "" +msgstr "URL do Transaction Mining Service" #: src/screens/NetworkSettings/CustomNetworkSettingsScreen.js:271 msgid "Wallet Service URL (optional)" @@ -1610,7 +1610,7 @@ msgstr "Dados do Oracle para assinar" #: src/components/Reown/SignOracleDataRequest.js:42 msgid "Oracle" -msgstr "" +msgstr "Oracle" #: src/components/Reown/WarnDisclaimer.js:27 msgid "" From e67c2dc6c87b1c1c950dda4f54a0f1b70099b92f Mon Sep 17 00:00:00 2001 From: tuliomir Date: Fri, 28 Mar 2025 18:28:26 -0300 Subject: [PATCH 3/5] docs: improves wording --- scripts/update_translations.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/update_translations.js b/scripts/update_translations.js index c9892d284..9c44b1202 100644 --- a/scripts/update_translations.js +++ b/scripts/update_translations.js @@ -25,6 +25,7 @@ const { tmpdir } = require('node:os'); * - Running all the translation steps as described above * - Checking if the `.pot` file is outdated * - Checking if all `.po` files have all messages from the `.pot` file + * - Checking if the mandatory languages have all translations in place in their `.po` files * - Checking for any fuzzy tags in the `.po` files * - Exiting with code 1 and failing if any of the above checks fail * - Lastly, checking for filesystem changes using `git status` for easier debugging, if needed From 08acfdb819ce2d4fdf11e6e25c2dbb71c614e71d Mon Sep 17 00:00:00 2001 From: tuliomir Date: Fri, 28 Mar 2025 18:34:26 -0300 Subject: [PATCH 4/5] docs: usage examples --- scripts/update_translations.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/update_translations.js b/scripts/update_translations.js index 9c44b1202..03332ce90 100644 --- a/scripts/update_translations.js +++ b/scripts/update_translations.js @@ -31,6 +31,13 @@ const { tmpdir } = require('node:os'); * - Lastly, checking for filesystem changes using `git status` for easier debugging, if needed */ +/* + * Usage: + * node scripts/update_translations.js + * node scripts/update_translations.js --ci-validation + * node scripts/update_translations.js --ci-validation --strict-languages=pt-br,ru-ru + */ + /** * All translations that should exist in the `locale` folder. Some of those may be incomplete. * @type {string[]} From 31e8b02b96e9219e3a94becb9d912c186104ff72 Mon Sep 17 00:00:00 2001 From: tuliomir Date: Fri, 28 Mar 2025 19:42:58 -0300 Subject: [PATCH 5/5] chore: improves input parsing --- scripts/update_translations.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/scripts/update_translations.js b/scripts/update_translations.js index 03332ce90..778f52764 100644 --- a/scripts/update_translations.js +++ b/scripts/update_translations.js @@ -261,9 +261,27 @@ function getCliParameters() { parameters[key.replace('--', '')] = value || true; }); + // Sanitize ci validation input + const ciValidationParam = parameters['ci-validation']; + if (ciValidationParam && (typeof ciValidationParam !== 'boolean')) { + console.warn(`❌ Must not offer any value for --ci-validation.`); + process.exit(1); + } + + // Sanitize languages input, removing empty strings and using the default value if none provided + const strictLanguagesParam = parameters['strict-languages']; + if (strictLanguagesParam && (typeof strictLanguagesParam !== 'string')) { + console.warn(`❌ Invalid value for --strict-languages. Usage: node update_translations.js --ci-validation --strict-languages=ru-ru,da`); + process.exit(1); + } + const sanitizedLanguagesInput = strictLanguagesParam?.split(',').filter((lang) => lang) || []; + const treatedLanguagesParam = sanitizedLanguagesInput?.length + ? sanitizedLanguagesInput + : mandatoryTranslations; + return { - isCiValidationRun: parameters['ci-validation'] || false, - strictLanguages: parameters['strict-languages']?.split(',') || mandatoryTranslations, + isCiValidationRun: ciValidationParam || false, + strictLanguages: treatedLanguagesParam, } }