From c1c7f9695d26b90dfe342601f57c4cd1b92fb901 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 22 Feb 2022 16:03:17 +0100 Subject: fix "no translation file found for domain" error --- src/hydrilla/util/_util.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src') 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 -- cgit v1.2.3