Skip to content

Commit

Permalink
Merge pull request #273 from Ouranosinc/better-notrans-error
Browse files Browse the repository at this point in the history
Better error when translations are not compiled
  • Loading branch information
aulemahal authored Oct 26, 2023
2 parents 56c9b0d + 6a13633 commit a56041e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
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

0 comments on commit a56041e

Please sign in to comment.