summaryrefslogtreecommitdiff
path: root/src/hydrilla/util
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-02-22 16:03:17 +0100
committerWojtek Kosior <koszko@koszko.org>2022-02-22 16:03:17 +0100
commitc1c7f9695d26b90dfe342601f57c4cd1b92fb901 (patch)
tree1ea3c8f69c41846f30e68154f92502815d6c0cdc /src/hydrilla/util
parent0fe371dab386dc4aeb08e601a91d61469f2f5f7a (diff)
downloadhydrilla-builder-2fcad7fc699b9cfb13c1028f7ebe512999d08208.tar.gz
hydrilla-builder-2fcad7fc699b9cfb13c1028f7ebe512999d08208.zip
fix "no translation file found for domain" errorv1.0-beta1
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