Skip to content

Commit

Permalink
Let get_translation accept any python path
Browse files Browse the repository at this point in the history
In 0.23 a regression was introduced that forced the use of
`get_translation(__package__)` instead of `get_translation(__name__`).
This change adds a fallback to allow the old style alongside.
It may however be removed in the future.

Fixes pulp#874
  • Loading branch information
mdellweg committed Jan 22, 2024
1 parent 5e5de8f commit 197c548
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/874.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a regression introduced in `get_translations`.
10 changes: 8 additions & 2 deletions pulp-glue/pulp_glue/common/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@ def get_translation(name: str) -> gettext.NullTranslations:
_ = translation.gettext
```
"""
localedir = files(name) / "locale"
return gettext.translation("messages", localedir=str(localedir), fallback=True)
name_parts = name.split(".")
while name_parts:
try:
localedir = files(".".join(name_parts)) / "locale"
return gettext.translation("messages", localedir=str(localedir), fallback=True)
except TypeError:
name_parts.pop()
raise TypeError(f"No package found for {name}.")

0 comments on commit 197c548

Please sign in to comment.