Skip to content

Commit

Permalink
fix: Gracefully handle exceptions during direct i18n loading
Browse files Browse the repository at this point in the history
If translations.py doesn't exist, MCprep moves to direct i18n, which
directly uses MO files for translations (at the cost of some UI updating
issues). However, if these MO files do not exist, then MCprep will throw
an exception. Since this exception occurs in the creation of
`MCprepEnv`, MCprep is rendered unusable.

This patch adds a basic try-except statement to allow `MCprepEnv` to
handle these exceptions gracefully.

Signed-off-by: Mahid Sheikh <mahid@standingpad.org>
  • Loading branch information
StandingPadAnimations committed Aug 23, 2024
1 parent ad363b5 commit 94264ea
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions MCprep_addon/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,21 @@ def __init__(self):
# i18n using Python's gettext module
#
# This only runs if translations.py does not exist
if not self.translations.exists():
self.languages: dict[str, gettext.NullTranslations] = {}
for language in self.languages_folder.iterdir():
self.languages[language.name] = gettext.translation("mcprep",
self.languages_folder,
fallback=True,
languages=[language.name])
try:
if not self.translations.exists():
self.languages: dict[str, gettext.NullTranslations] = {}
for language in self.languages_folder.iterdir():
self.languages[language.name] = gettext.translation("mcprep",
self.languages_folder,
fallback=True,
languages=[language.name])
self.use_direct_i18n = True
self.log("Loaded direct i18n!")

except Exception:
self.languages = {}
self.log("Exception occured while loading translations!")


# This allows us to translate strings on the fly
def _(self, msg: str) -> str:
Expand Down

0 comments on commit 94264ea

Please sign in to comment.