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

Better error when translations are not compiled #273

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/goodtoknow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Which can also be activated in the code using :py:func:`xclim.core.options.set_o

Translation is of course not automatic but relies on manually populated `gettext <https://docs.python.org/3/library/gettext.html?highlight=gettext#module-gettext>`_ catalogs. xscen ships with a catalog of french (fr) translations. See :ref:`translating-xscen` to learn how to add translations to xscen. xclim's documentation of the same subject is `here <https://xclim.readthedocs.io/en/stable/internationalization.html>`_.

If your xscen is installed in "editable" mode in its source directory (``pip install -e .``), you should run ``make translate`` each time you pull changes from the upstream source.

Module-wide options
-------------------

Expand Down
16 changes: 10 additions & 6 deletions xscen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@
If a language is not defined or a message not translated, the function will return the raw message.
"""


for loc in (Path(__file__).parent / "data").iterdir():
if loc.is_dir() and len(loc.name) == 2:
TRANSLATOR[loc.name] = gettext.translation(
"xscen", localedir=loc.parent, languages=[loc.name]
).gettext
try:
for loc in (Path(__file__).parent / "data").iterdir():
if loc.is_dir() and len(loc.name) == 2:
TRANSLATOR[loc.name] = gettext.translation(
"xscen", localedir=loc.parent, languages=[loc.name]
).gettext
except FileNotFoundError as err:
raise ImportError(
"Your xscen installation doesn't have compiled translations. Run `make translate` from the source directory to fix."
) from err


def update_attr(ds, attr, new, others=None, **fmt):
Expand Down