Better determine language cross platform
This commit is contained in:
parent
4aca2eeae2
commit
d200e94fba
|
@ -69,6 +69,22 @@ def iter_locale_dirs():
|
||||||
if locale_dir.is_dir():
|
if locale_dir.is_dir():
|
||||||
yield str(locale_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():
|
def initialize_direction_mark():
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
|
||||||
|
@ -137,15 +153,13 @@ try:
|
||||||
except locale.Error as error:
|
except locale.Error as error:
|
||||||
print(error)
|
print(error)
|
||||||
|
|
||||||
if os.name == 'nt':
|
try:
|
||||||
try:
|
LANG = get_default_lang()
|
||||||
# en_US, fr_FR, el_GR etc..
|
print('Found default language: %s' % LANG)
|
||||||
default = locale.getdefaultlocale()[0]
|
except Exception as error:
|
||||||
if default is not None:
|
print('Failed to determine default language')
|
||||||
LANG = default[:2]
|
import traceback
|
||||||
except (ValueError, locale.Error):
|
traceback.print_exc()
|
||||||
pass
|
|
||||||
os.environ['LANG'] = LANG
|
|
||||||
|
|
||||||
# Search for the translation in all locale dirs
|
# Search for the translation in all locale dirs
|
||||||
for dir_ in iter_locale_dirs():
|
for dir_ in iter_locale_dirs():
|
||||||
|
|
Loading…
Reference in New Issue