Skip to content

[candidate_list] Translate candidate_list module #9797

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

driusan
Copy link
Collaborator

@driusan driusan commented May 16, 2025

This translates the candidate list module as an example of how to do localization of a loris module that is written in React with class based components.

JSON files are generated from the same .po files used by the PHP side of file, which are then imported into the i18next resources. They are generated at compile time with the i18next-conv package. Modules (in this case candidate_list) must call the addResourceBundle method of i18next to add the strings which are specific to their module.

This example uses the withTranslation HOC, but functional components can use the useTranslation hook instead.

Note that in this PR I only translated the strings from the candidate_list module itself used by the filters/headers to serve as an example. There are other strings which come from components in the jsx/ directory which are shared across all modules. Those will be in other PRs since they are a one-time effort for all modules.

This translates the candidate list module as an example of how
to do localization of a loris module that is written in React
with class based components.
@github-actions github-actions bot added Language: PHP PR or issue that update PHP code Language: Javascript PR or issue that update Javascript code Module: candidate_list PR or issue related to candidate_list module labels May 16, 2025
@driusan driusan force-pushed the TranslateCandidateList branch from 0a97362 to 4cc141e Compare May 16, 2025 19:37
};

window.addEventListener('load', () => {
const args = QueryString.get();
i18n.addResourceBundle('ja', 'candidate_list', jaStrings);
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this only get added if the user preference is japanese? if we were to add support for more languages, would each language bundle need to be added here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The resource bundle gets added for all users in the javascript but will only get used if the language is ja. We would need to add each language call here.

If we use a backend different loader than the json object resources way in i18next (ie if we used the http backend), there is an option to only load the used language, but since it's being compiled into the module's js here I don't think there's any reason to not just add the resources.

@@ -21,3 +21,20 @@ msgstr ""
msgid "Access Profile"
msgstr ""

msgid "Entity Type"
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a way to combine these so that we have the msgid, and then have all the listed translations? Or is this the standard way to do it? It just seems that it would be easier to maintain with the msgids written once, rather than repeated across files.

Copy link
Collaborator Author

@driusan driusan May 23, 2025

Choose a reason for hiding this comment

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

No, this is a standard way to do it. All the translations to the same language are grouped together, not all the different language translations for a given string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Language: Javascript PR or issue that update Javascript code Language: PHP PR or issue that update PHP code Module: candidate_list PR or issue related to candidate_list module Multilingual Any tasks related to making LORIS multilingual
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants