From e54ec6f8b3dd1884e804c7837f4a8675349d2073 Mon Sep 17 00:00:00 2001 From: tabarra Date: Tue, 12 Sep 2023 21:16:25 -0300 Subject: [PATCH] chore: improved locale checker and translation doc --- docs/translation.md | 2 ++ scripts/locale-utils.js | 45 ++++++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/docs/translation.md b/docs/translation.md index a2061612c..643d92b9e 100644 --- a/docs/translation.md +++ b/docs/translation.md @@ -14,7 +14,9 @@ For that you will need to: - Make a custom locale file with the instructions above; - Name the file using the language code in [this page](https://www.science.co.il/language/Locale-codes.php); - The `$meta.label` must be the language name in English (eg `Spanish` instead of `EspaƱol`); +- If you create a new translation, make sure to add it to `shared/localeMap.ts`, and maintain the alphabetical order; - Do a [Pull Request](https://github.com/tabarra/txAdmin/pulls) posting a few screenshots of evidence that you tested what you changed in-game. +- An automatic check will run, make sure to read the output in case of any errors. > **Pro Tip:** To quickly test your changes, you can edit the `locale.json` file and then in the settings page click "Save Global Settings" again to see the changes in the game menu without needing to restart txAdmin or the server. diff --git a/scripts/locale-utils.js b/scripts/locale-utils.js index ea1ce55e0..198010085 100644 --- a/scripts/locale-utils.js +++ b/scripts/locale-utils.js @@ -198,29 +198,32 @@ const checkCommand = () => { errorsFound.push([key, `${errorType} key`]); } - // Checking specials (placeholders or smart time division) - const keysWithDiffSpecials = defaultLocaleKeys.filter((k) => { - return xor(defaultLocaleParsed[k].specials, parsedLocale[k].specials).length; - }); - for (const key of keysWithDiffSpecials) { - const defaultSpecialsString = JSON.stringify(defaultLocaleParsed[key].specials); - errorsFound.push([key, `must contain the placeholders ${defaultSpecialsString}`]); - } + // Skip the rest of the checks if there are missing/excess keys + if (!diffKeys.length) { + // Checking specials (placeholders or smart time division) + const keysWithDiffSpecials = defaultLocaleKeys.filter((k) => { + return xor(defaultLocaleParsed[k].specials, parsedLocale[k].specials).length; + }); + for (const key of keysWithDiffSpecials) { + const defaultSpecialsString = JSON.stringify(defaultLocaleParsed[key].specials); + errorsFound.push([key, `must contain the placeholders ${defaultSpecialsString}`]); + } - // Check for untrimmed strings - const keysWithUntrimmedStrings = parsedLocaleKeys.filter((k) => { - return parsedLocale[k].value !== parsedLocale[k].value.trim(); - }); - for (const key of keysWithUntrimmedStrings) { - errorsFound.push([key, `untrimmed string`]); - } + // Check for untrimmed strings + const keysWithUntrimmedStrings = parsedLocaleKeys.filter((k) => { + return parsedLocale[k].value !== parsedLocale[k].value.trim(); + }); + for (const key of keysWithUntrimmedStrings) { + errorsFound.push([key, `untrimmed string`]); + } - // Checking empty strings - const keysWithEmptyStrings = parsedLocaleKeys.filter((k) => { - return parsedLocale[k].value === ''; - }); - for (const key of keysWithEmptyStrings) { - errorsFound.push([key, `empty string`]); + // Checking empty strings + const keysWithEmptyStrings = parsedLocaleKeys.filter((k) => { + return parsedLocale[k].value === ''; + }); + for (const key of keysWithEmptyStrings) { + errorsFound.push([key, `empty string`]); + } } // Print errors