force lang in env
This commit is contained in:
parent
7764fa9b43
commit
49f1cda4d3
1 changed files with 19 additions and 14 deletions
|
@ -18,10 +18,12 @@
|
||||||
# the rough gus of pypy: pypy: http://codespeak.net/svn/pypy/dist/pypy/config/
|
# the rough gus of pypy: pypy: http://codespeak.net/svn/pypy/dist/pypy/config/
|
||||||
# the whole pypy projet is under MIT licence
|
# the whole pypy projet is under MIT licence
|
||||||
"internationalisation utilities"
|
"internationalisation utilities"
|
||||||
|
from .log import log
|
||||||
|
|
||||||
from gettext import translation, NullTranslations
|
from gettext import translation, NullTranslations
|
||||||
from platform import system
|
from platform import system
|
||||||
from pkg_resources import resource_filename
|
from pkg_resources import resource_filename
|
||||||
from .log import log
|
from os import environ
|
||||||
|
|
||||||
|
|
||||||
DEFAULT = 'en'
|
DEFAULT = 'en'
|
||||||
|
@ -35,22 +37,25 @@ def get_translation() -> str:
|
||||||
app_name = __name__[:-5]
|
app_name = __name__[:-5]
|
||||||
translations_path = resource_filename(app_name, 'locale')
|
translations_path = resource_filename(app_name, 'locale')
|
||||||
|
|
||||||
if 'Windows' in system():
|
if 'TIRAMISU_LOCALE' in environ:
|
||||||
import ctypes
|
user_locale = environ['TIRAMISU_LOCALE']
|
||||||
from locale import windows_locale
|
|
||||||
default_locale = windows_locale[ctypes.windll.kernel32.GetUserDefaultUILanguage()]
|
|
||||||
else:
|
else:
|
||||||
from locale import getdefaultlocale
|
if 'Windows' in system():
|
||||||
default_locale = getdefaultlocale()
|
import ctypes
|
||||||
if default_locale and isinstance(default_locale, tuple):
|
from locale import windows_locale
|
||||||
if default_locale[0] is not None:
|
default_locale = windows_locale[ctypes.windll.kernel32.GetUserDefaultUILanguage()]
|
||||||
user_locale = default_locale[0][:2]
|
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:
|
else:
|
||||||
user_locale = DEFAULT
|
user_locale = DEFAULT
|
||||||
elif default_locale:
|
|
||||||
user_locale = default_locale[:2]
|
|
||||||
else:
|
|
||||||
user_locale = DEFAULT
|
|
||||||
try:
|
try:
|
||||||
trans = translation(domain=app_name,
|
trans = translation(domain=app_name,
|
||||||
localedir=translations_path,
|
localedir=translations_path,
|
||||||
|
|
Loading…
Reference in a new issue