summaryrefslogtreecommitdiff
path: root/src/hydrilla/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/hydrilla/util')
-rw-r--r--src/hydrilla/util/_util.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/hydrilla/util/_util.py b/src/hydrilla/util/_util.py
index 46baa0e..dc18fb9 100644
--- a/src/hydrilla/util/_util.py
+++ b/src/hydrilla/util/_util.py
@@ -145,13 +145,18 @@ def translation(localedir: Union[Path, str], lang: Optional[str]=None) \
# https://stackoverflow.com/questions/3425294/how-to-detect-the-os-default-language-in-python
# But I am not going to surrender to Microbugs' nonfree, crappy OS to test
# it, to the lines inside try: may fail.
- try:
- from ctypes.windll import kernel32 as windll
- lang = locale.windows_locale[windll.GetUserDefaultUILanguage()]
- except:
- lang = locale.getdefaultlocale()[0] or 'C'
+ if lang is None:
+ try:
+ from ctypes.windll import kernel32 as windll
+ lang = locale.windows_locale[windll.GetUserDefaultUILanguage()]
+ except:
+ lang = locale.getdefaultlocale()[0] or 'en_US'
+
+ localedir = Path(localedir)
+ if not (localedir / lang).is_dir():
+ lang = 'en_US'
return gettext.translation('hydrilla-messages', localedir=localedir,
- languages=[lang, 'en_US'])
+ languages=[lang])
_ = translation(here.parent / 'builder' / 'locales').gettext