-
-
Notifications
You must be signed in to change notification settings - Fork 156
/
i18n.py
74 lines (60 loc) · 1.37 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
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python
# encoding: utf-8
# standard library imports
import gettext
import json
import locale
import os
import sys
__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",
"af_AF": "Afrikaans",
"ar_SA": "Arabic",
"cs_CZ": "Czech",
"fr_FR": "French",
"de_DE": "German",
"gr_GR": "Greek",
"it_IT": "Italian",
"pl_PL": "Polish",
"pt_PT": "Portuguese",
"sl_SL": "Slovenian",
"es_ES": "Spanish",
"ta_TA": "Tamil",
}
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("sip_messages", localedir)
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:
install_kwargs = {}
if sys.version_info.major == 2:
install_kwargs['unicode'] = True
gettext.translation("sip_messages", localedir, languages=[ui_lang]).install(**install_kwargs)
except IOError:
pass