forked from Dan-in-CA/SIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi18n.py
72 lines (58 loc) · 1.35 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
#!/usr/bin/python
# encoding: utf-8
import gettext
import json
import locale
import os
import sys
__author__ = u"Dan"
try:
with open(u"./data/sd.json", u"r") as sdf:
sd_temp = json.load(sdf)
except:
pass
try:
sd_lang = sd_temp[u"lang"]
except:
sd_lang = u"default"
languages = {
u"en_US": u"English",
u"af_AF": u"Afrikaans",
u"ar_SA": u"Arabic",
u"cs_CZ": u"Czech",
u"fr_FR": u"French",
u"de_DE": u"German",
u"gr_GR": u"Greek",
u"it_IT": u"Italian",
u"pt_PT": u"Portuguese",
u"sl_SL": u"Slovenian",
u"es_ES": u"Spanish",
u"ta_TA": u"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 + u"/i18n"
gettext.install(u"sip_messages", localedir)
sys_lang = get_system_lang()
if sd_lang == u"default":
if sys_lang in languages:
ui_lang = sys_lang
else:
ui_lang = u"en_US"
else:
ui_lang = sd_lang
try:
install_kwargs = {}
if sys.version_info.major == 2:
install_kwargs['unicode'] = True
gettext.translation(u"sip_messages", localedir, languages=[ui_lang]).install(**install_kwargs)
except IOError:
pass