Skip to content
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

i18n scripts improvements #559

Merged
merged 4 commits into from
Jan 6, 2025
Merged

Conversation

Fredx87
Copy link
Contributor

@Fredx87 Fredx87 commented Jan 3, 2025

Description

This PR adds some improvements to the scripts used for downloading and extracting translation strings for the JS modules. The scripts were added when we had only one module, so they needed some tweaks to make it easier to work with multiple modules.

bin/update-modules-translations.mjs

  • Removed the MODULES mapping. Now the script searches for all the files matching the src/modules/**/translations/en-us.yml glob and downloads the translation files.

bin/extract-strings.mjs

  • Removed the need to specify the package name, source file glob, and output file as args. The script now searches for all the files matching the src/modules/**/translations/en-us.yml glob and extracts strings for each module using the src/modules/[MODULE_NAME]/**/*.{ts,tsx} glob.
  • Added the ability to extract strings for all modules or a single module, passing a --module parameter.
  • The script now doesn't mark removed strings as obsolete by default, but it has a new --mark-obsolete flag. Sometimes we remove some strings on a branch but we want to deprecate them later when we merge the branch on master
  • We have new i18n guidelines requiring us to provide strings for all possible plural form values (zero, one, two, few, many, other). The script has been updated to extract all the needed strings for plurals.

Note

I ran the extract-strings script on master and service-catalog branches and found some inconsistencies in the strings used in the source code and the translation files, for example:

We will need to open other PRs to fix these issue.

Checklist

  • 📗 all commit messages follow the conventional commits standard
  • ⬅️ changes are compatible with RTL direction
  • ♿ Changes to the UI are tested for accessibility and compliant with WCAG 2.1.
  • 📝 changes are tested in Chrome, Firefox, Safari and Edge
  • 📱 changes are responsive and tested in mobile
  • 👍 PR is approved by @zendesk/vikings

Copy link
Contributor

@melzreal melzreal left a comment

Choose a reason for hiding this comment

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

LGTM as far as I understand it, likely could do with a second set of 👀 for testing

// locale that need exactly the ".zero", ".one", ".other" keys, even if we are extracting English strings
locales: ["lv"],
// locale that need exactly the 6 forms, even if we are extracting English strings
locales: ["ar"],
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why make ar the default instead of en

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is explained in the comment above the line:

  • our translation system requires us to define 6 keys for plurals ([key].zero,[key].one, [key].two, [key].few, [key].many, [key].other)
  • the tool we use (i18next-parsers) extracts these plural keys based on the source locale. Since English has only one and other forms, if we set en as the source locale it would extract only [key].one and [key].other
  • ar has all six forms, so setting it as the source locale has the effect of letting the tool extract all the needed strings

@gosiexon-zen
Copy link
Contributor

I ran the extract-strings script on master and service-catalog branches and found some inconsistencies in the strings used in the source code and the translation files, for example:

My bad, sorry. I have PR opened with fetching translations for this new-request-form.attachments.remove-file-aria-label so I can update the label in the code.

@Fredx87 Fredx87 merged commit aa1b516 into master Jan 6, 2025
5 checks passed
@Fredx87 Fredx87 deleted the gianluca/i18n-scripts-improvements branch January 6, 2025 10:11
@zd-svc-github-copenhagen-theme
Copy link
Collaborator

🎉 This PR is included in version 4.2.6 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants