mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-07 00:48:41 +00:00
[i18n] Refactor loading libintl library
Handle different names for libintl library on MacOS and Windows with fallback.
This commit is contained in:
parent
f16afc59ba
commit
0d6eec7a33
1 changed files with 19 additions and 11 deletions
|
@ -116,22 +116,30 @@ def setup_translation():
|
||||||
gettext.install(I18N_DOMAIN, translations_path, names=['ngettext'], **kwargs)
|
gettext.install(I18N_DOMAIN, translations_path, names=['ngettext'], **kwargs)
|
||||||
builtins.__dict__['_n'] = builtins.__dict__['ngettext']
|
builtins.__dict__['_n'] = builtins.__dict__['ngettext']
|
||||||
|
|
||||||
libintl = None
|
def load_libintl(libintls):
|
||||||
if deluge.common.windows_check():
|
errors = []
|
||||||
for intl in ('libintl-8.dll', 'intl.dll'):
|
for library in libintls:
|
||||||
try:
|
try:
|
||||||
libintl = ctypes.cdll.LoadLibrary(intl)
|
libintl = ctypes.cdll.LoadLibrary(library)
|
||||||
except OSError as ex:
|
except OSError as ex:
|
||||||
exception = ex
|
errors.append(ex)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
finally:
|
|
||||||
if not libintl:
|
if not libintl:
|
||||||
log.error('Unable to initialize gettext/locale!')
|
log.debug(
|
||||||
log.error(exception)
|
'Unable to initialize gettext/locale:\n %s', '\n '.join(errors)
|
||||||
|
)
|
||||||
setup_mock_translation()
|
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():
|
elif deluge.common.osx_check():
|
||||||
libintl = ctypes.cdll.LoadLibrary('libintl.dylib')
|
libintl = load_libintl(['libintl.8.dylib', 'libintl.dylib'])
|
||||||
|
|
||||||
if libintl:
|
if libintl:
|
||||||
libintl.bindtextdomain(
|
libintl.bindtextdomain(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue