/
messages.py
executable file
·83 lines (66 loc) · 2.24 KB
/
messages.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
75
76
77
78
79
80
81
82
83
# coding:utf8
from syncplay import constants
from . import messages_en
from . import messages_ru
from . import messages_de
from . import messages_it
from . import messages_es
from . import messages_pt_BR
messages = {
"en": messages_en.en,
"ru": messages_ru.ru,
"de": messages_de.de,
"it": messages_it.it,
"es": messages_es.es,
"es": messages_pt_BR.pt_BR,
"CURRENT": None
}
def getLanguages():
langList = {}
for lang in messages:
if lang != "CURRENT":
langList[lang] = getMessage("LANGUAGE", lang)
return langList
def setLanguage(lang):
messages["CURRENT"] = lang
def getMissingStrings():
missingStrings = ""
for lang in messages:
if lang != "en" and lang != "CURRENT":
for message in messages["en"]:
if message not in messages[lang]:
missingStrings = missingStrings + "({}) Missing: {}\n".format(lang, message)
for message in messages[lang]:
if message not in messages["en"]:
missingStrings = missingStrings + "({}) Unused: {}\n".format(lang, message)
return missingStrings
def getInitialLanguage():
import locale
try:
initialLanguage = locale.getdefaultlocale()[0].split("_")[0]
if initialLanguage not in messages:
initialLanguage = constants.FALLBACK_INITIAL_LANGUAGE
except:
initialLanguage = constants.FALLBACK_INITIAL_LANGUAGE
return initialLanguage
def isValidLanguage(language):
return language in messages
def getMessage(type_, locale=None):
if constants.SHOW_TOOLTIPS == False:
if "-tooltip" in type_:
return ""
if not isValidLanguage(messages["CURRENT"]):
setLanguage(getInitialLanguage())
lang = messages["CURRENT"]
if locale and locale in messages:
if type_ in messages[locale]:
return str(messages[locale][type_])
if lang and lang in messages:
if type_ in messages[lang]:
return str(messages[lang][type_])
if type_ in messages["en"]:
return str(messages["en"][type_])
else:
print("WARNING: Cannot find message '{}'!".format(type_))
#return "!{}".format(type_) # TODO: Remove
raise KeyError(type_)