Skip to content

chore: Add pt-br as a mandatory language on CI #673

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

Merged
merged 5 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions locale/pt-br/texts.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)"
Expand Down Expand Up @@ -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 ""
Expand Down
52 changes: 46 additions & 6 deletions scripts/update_translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,31 @@ 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
*/

/*
* 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[]}
*/
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 = [];

/**
Expand Down Expand Up @@ -107,10 +126,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';
Expand All @@ -121,7 +140,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' });
Expand Down Expand Up @@ -227,8 +249,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,
Copy link
Preview

Copilot AI Mar 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When '--strict-languages' is provided with an empty value, splitting it will return [''] instead of defaulting to mandatoryTranslations. Consider adding a check to use mandatoryTranslations if the resulting array is empty or contains an empty string.

Suggested change
strictLanguages: parameters['strict-languages']?.split(',') || mandatoryTranslations,
strictLanguages: (parameters['strict-languages']?.split(',').filter(lang => lang) || mandatoryTranslations).length ? parameters['strict-languages']?.split(',').filter(lang => lang) : mandatoryTranslations,

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed in 31e8b02

}
}

try {
const isCiValidationRun = process.argv.includes('--ci-validation');
const { isCiValidationRun, strictLanguages } = getCliParameters();

runLocaleUpdatePot();
mergeTranslations();
Expand All @@ -243,7 +283,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.`);
Expand Down