diff options
author | Calum Lind <calumlind+deluge@gmail.com> | 2021-04-17 18:57:20 +0100 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2021-07-25 16:47:14 +0100 |
commit | 0d6eec7a33e66380a310ceb562b6570ddc8265d4 (patch) | |
tree | 8177a5a5e6813355799af04afd888491e1029e49 | |
parent | f16afc59ba84d6535ed90d90119cc4e7012a504d (diff) | |
download | deluge-0d6eec7a33e66380a310ceb562b6570ddc8265d4.tar.gz deluge-0d6eec7a33e66380a310ceb562b6570ddc8265d4.tar.bz2 deluge-0d6eec7a33e66380a310ceb562b6570ddc8265d4.zip |
[i18n] Refactor loading libintl library
Handle different names for libintl library on MacOS and Windows with
fallback.
-rw-r--r-- | deluge/i18n/util.py | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/deluge/i18n/util.py b/deluge/i18n/util.py index d33acaadf..81530c2ee 100644 --- a/deluge/i18n/util.py +++ b/deluge/i18n/util.py @@ -116,22 +116,30 @@ def setup_translation(): gettext.install(I18N_DOMAIN, translations_path, names=['ngettext'], **kwargs) builtins.__dict__['_n'] = builtins.__dict__['ngettext'] - libintl = None - if deluge.common.windows_check(): - for intl in ('libintl-8.dll', 'intl.dll'): + def load_libintl(libintls): + errors = [] + for library in libintls: try: - libintl = ctypes.cdll.LoadLibrary(intl) + libintl = ctypes.cdll.LoadLibrary(library) except OSError as ex: - exception = ex + errors.append(ex) else: break - finally: - if not libintl: - log.error('Unable to initialize gettext/locale!') - log.error(exception) - setup_mock_translation() + + if not libintl: + log.debug( + 'Unable to initialize gettext/locale:\n %s', '\n '.join(errors) + ) + setup_mock_translation() + return + + return libintl + + libintl = None + if deluge.common.windows_check(): + libintl = load_libintl(['libintl-8.dll', 'intl.dll']) elif deluge.common.osx_check(): - libintl = ctypes.cdll.LoadLibrary('libintl.dylib') + libintl = load_libintl(['libintl.8.dylib', 'libintl.dylib']) if libintl: libintl.bindtextdomain( |