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

Use gettext/Babel/i18n-generator for true i18n support in xclim UI #271

Open
2 tasks done
Zeitsperre opened this issue Oct 11, 2022 · 0 comments
Open
2 tasks done

Comments

@Zeitsperre
Copy link
Contributor

Addressing a Problem?

Xclim presently offers translations of indicator metadata. The method by which we perform this currently is a YAML file of mappings, with some special features to handle conjugations and gender of words when mapped (for French, currently). This approach (or the promising approach using jinja2, as detailed in Ouranosinc/xclim#1120) is adequate for now, seeing as indicator metadata is highly conditional and complex.

Outside the metadata translations, the internal documentation and all output messages remain in English, but they could be translated using a very standardized/Pythonic approach. Worth investigating?

Potential Solution

Existing tools in the Python standard library and in PyPI have been developed specifically for addressing these needs:

  • gettext
    • Provides a means of setting messages and logs (and anything based on str classes) to be locale-dependent. This library gives us the low-level functionality that handles translations.
  • Babel
    • A library that helps in creating translation catalogues (similar to our YAML translation approach), that can replace messages on the fly based on locale and other factors. Has support for date-time with timezone conversion, number format parsing/reformatting (1,0001.000), and means of providing installation options that are locale-dependent.
  • i18n-generator
    • A library that can be used for translating text. Would be useful for populating fields necessary in a YAML mapping / language conversion catalogue.

One potential approach would be to perform the following:

  • Identify and convert all logs, messages to the user to the gettext string class.
  • Run Babel to generate catalogue mappings for all affected str instances.
  • Provide the French (or other) language mappings for the messages of note via i18n-generator.
  • Integrate Babel-based language conversion into the setup.py of xclim.

The result of this process will be that xclim's UI, history output, logs, etc. can now reflect the language of the environment (or manually overridden) for a much more consistent UX.

Additional context

Resources:

Contribution

  • I would be willing/able to open a Pull Request to contribute this feature.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Zeitsperre Zeitsperre changed the title Use gettext/Babel/i18n-genertator for true i18n support in xclim UI Use gettext/Babel/i18n-generator for true i18n support in xclim UI Oct 11, 2022
@huard huard transferred this issue from Ouranosinc/xclim Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant