forked from Dan-in-CA/SIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18n.py
61 lines (48 loc) · 1.08 KB
/
i18n.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
# encoding: utf-8
import os
import locale
import gettext
import json
__author__ = 'Dan'
try:
with open('./data/sd.json', 'r') as sdf:
sd_temp = json.load(sdf)
except:
pass
try:
sd_lang = sd_temp['lang']
except:
sd_lang = 'default'
languages = ({
"en_US": "English",
"cs_CZ": "Czech",
"fr_FR": "French",
"de_DE": "German",
"sl_SL": "Slovenian",
"es_ES": "Spanish",
})
def get_system_lang():
"""Return default system locale language"""
lc, encoding = locale.getdefaultlocale()
if lc:
return lc
else:
return None
# File location directory.
curdir = os.path.abspath(os.path.dirname(__file__))
# i18n directory.
localedir = curdir + '/i18n'
gettext.install('ospi_messages', localedir, unicode=True)
sys_lang = get_system_lang()
if sd_lang == 'default':
if sys_lang in languages:
ui_lang = sys_lang
else:
ui_lang = 'en_US'
else:
ui_lang = sd_lang
try:
gettext.translation('ospi_messages', localedir, languages=[ui_lang]).install(True)
except IOError:
pass