[Git][gajim/gajim][master] Better determine language cross platform

Philipp Hörist gitlab at dev.gajim.org
Sat Jan 5 16:27:27 CET 2019


Philipp Hörist pushed to branch master at gajim / gajim


Commits:
d200e94f by Philipp Hörist at 2019-01-05T15:27:11Z
Better determine language cross platform

- - - - -


1 changed file:

- gajim/common/i18n.py


Changes:

=====================================
gajim/common/i18n.py
=====================================
@@ -69,6 +69,22 @@ def iter_locale_dirs():
         if locale_dir.is_dir():
             yield str(locale_dir)
 
+def get_default_lang():
+    if os.name == "nt":
+        import ctypes
+        windll = ctypes.windll.kernel32
+        lang = locale.windows_locale[windll.GetUserDefaultUILanguage()]
+        return lang[:2]
+
+    if sys.platform == "darwin":
+        from AppKit import NSLocale
+        return NSLocale.currentLocale().languageCode()
+
+    default = locale.getdefaultlocale()[0]
+    if default is not None:
+        return default[:2]
+    return 'en'
+
 def initialize_direction_mark():
     from gi.repository import Gtk
 
@@ -137,15 +153,13 @@ try:
 except locale.Error as error:
     print(error)
 
-if os.name == 'nt':
-    try:
-        # en_US, fr_FR, el_GR etc..
-        default = locale.getdefaultlocale()[0]
-        if default is not None:
-            LANG = default[:2]
-    except (ValueError, locale.Error):
-        pass
-    os.environ['LANG'] = LANG
+try:
+    LANG = get_default_lang()
+    print('Found default language: %s' % LANG)
+except Exception as error:
+    print('Failed to determine default language')
+    import traceback
+    traceback.print_exc()
 
 # Search for the translation in all locale dirs
 for dir_ in iter_locale_dirs():



View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/d200e94fbacb7db1b271d013dd39b40d15e58ba7

-- 
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/d200e94fbacb7db1b271d013dd39b40d15e58ba7
You're receiving this email because of your account on dev.gajim.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gajim.org/pipermail/commits/attachments/20190105/bfd2f1c8/attachment-0001.html>


More information about the Commits mailing list