From 93c953521646d6ad598d8900414eefe351f856c5 Mon Sep 17 00:00:00 2001 From: Juhani Numminen Date: Mon, 12 Aug 2019 12:28:43 +0300 Subject: [PATCH] Detect LANG for gettext on android --- pysollib/init.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pysollib/init.py b/pysollib/init.py index 569481a1..4a56b023 100644 --- a/pysollib/init.py +++ b/pysollib/init.py @@ -27,6 +27,11 @@ import os import subprocess import sys +try: + import jnius +except ImportError: + jnius = None + import pysollib.settings # ************************************************************************ @@ -36,13 +41,14 @@ import pysollib.settings def init(): - if os.name == 'nt' and 'LANG' not in os.environ: - try: - loc = locale.getdefaultlocale() - os.environ['LANG'] = loc[0] - except Exception: - pass - # locale.setlocale(locale.LC_ALL, '') + if 'LANG' not in os.environ: + if os.name == 'nt': + lang, enc = locale.getdefaultlocale() + os.environ['LANG'] = lang + elif jnius: # android + Locale = jnius.autoclass('java.util.Locale') + os.environ['LANG'] = Locale.getDefault().getLanguage() + locale.setlocale(locale.LC_ALL, '') # install gettext # locale_dir = 'locale'