diff --git a/tiramisu/i18n.py b/tiramisu/i18n.py index 6947b39..1f624e8 100644 --- a/tiramisu/i18n.py +++ b/tiramisu/i18n.py @@ -18,10 +18,12 @@ # the rough gus of pypy: pypy: http://codespeak.net/svn/pypy/dist/pypy/config/ # the whole pypy projet is under MIT licence "internationalisation utilities" +from .log import log + from gettext import translation, NullTranslations from platform import system from pkg_resources import resource_filename -from .log import log +from os import environ DEFAULT = 'en' @@ -35,22 +37,25 @@ def get_translation() -> str: app_name = __name__[:-5] translations_path = resource_filename(app_name, 'locale') - if 'Windows' in system(): - import ctypes - from locale import windows_locale - default_locale = windows_locale[ctypes.windll.kernel32.GetUserDefaultUILanguage()] + if 'TIRAMISU_LOCALE' in environ: + user_locale = environ['TIRAMISU_LOCALE'] else: - from locale import getdefaultlocale - default_locale = getdefaultlocale() - if default_locale and isinstance(default_locale, tuple): - if default_locale[0] is not None: - user_locale = default_locale[0][:2] + if 'Windows' in system(): + import ctypes + from locale import windows_locale + default_locale = windows_locale[ctypes.windll.kernel32.GetUserDefaultUILanguage()] + else: + from locale import getdefaultlocale + default_locale = getdefaultlocale() + if default_locale and isinstance(default_locale, tuple): + if default_locale[0] is not None: + user_locale = default_locale[0][:2] + else: + user_locale = DEFAULT + elif default_locale: + user_locale = default_locale[:2] else: user_locale = DEFAULT - elif default_locale: - user_locale = default_locale[:2] - else: - user_locale = DEFAULT try: trans = translation(domain=app_name, localedir=translations_path,