Skip to content

Commit

Permalink
chore: improved locale checker and translation doc
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Sep 13, 2023
1 parent c16969a commit e54ec6f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
2 changes: 2 additions & 0 deletions docs/translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
45 changes: 24 additions & 21 deletions scripts/locale-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e54ec6f

Please sign in to comment.