3 from Tools.Directories import SCOPE_LANGUAGE, resolveFilename
9 gettext.install('enigma2', resolveFilename(SCOPE_LANGUAGE, ""), unicode=0, codeset="utf-8")
10 self.activeLanguage = 0
13 # FIXME make list dynamically
14 # name, iso-639 language, iso-3166 country. Please don't mix language&country!
15 # also, see "precalcLanguageList" below on how to re-create the language cache after you added a language
16 self.addLanguage(_("English"), "en", "EN")
17 self.addLanguage(_("German"), "de", "DE")
18 self.addLanguage(_("Arabic"), "ar", "AE")
19 self.addLanguage(_("Catalan"), "ca", "AD")
20 self.addLanguage(_("Croatian"), "hr", "HR")
21 self.addLanguage(_("Czech"), "cs", "CZ")
22 self.addLanguage(_("Danish"), "da", "DK")
23 self.addLanguage(_("Dutch"), "nl", "NL")
24 self.addLanguage(_("Finnish"), "fi", "FI")
25 self.addLanguage(_("French"), "fr", "FR")
26 self.addLanguage(_("Greek"), "el", "GR")
27 self.addLanguage(_("Hungarian"), "hu", "HU")
28 self.addLanguage(_("Lithuanian"), "lt", "LT")
29 self.addLanguage(_("Icelandic"), "is", "IS")
30 self.addLanguage(_("Italian"), "it", "IT")
31 self.addLanguage(_("Norwegian"), "no", "NO")
32 self.addLanguage(_("Polish"), "pl", "PL")
33 self.addLanguage(_("Portuguese"), "pt", "PT")
34 self.addLanguage(_("Russian"), "ru", "RU")
35 self.addLanguage(_("Spanish"), "es", "ES")
36 self.addLanguage(_("Swedish"), "sv", "SE")
37 self.addLanguage(_("Turkish"), "tr", "TR")
41 def addLanguage(self, name, lang, country):
43 self.lang[str(lang + "_" + country)] = ((_(name), lang, country))
44 self.langlist.append(str(lang + "_" + country))
46 print "Language " + str(name) + " not found"
48 def activateLanguage(self, index):
50 lang = self.lang[index]
51 print "Activating language " + lang[0]
52 gettext.translation('enigma2', resolveFilename(SCOPE_LANGUAGE, ""), languages=[lang[1]]).install()
53 self.activeLanguage = index
54 for x in self.callbacks:
57 print "Selected language does not exist!"
59 def activateLanguageIndex(self, index):
60 if index < len(self.langlist):
61 self.activateLanguage(self.langlist[index])
63 def getLanguageList(self):
65 for x in self.langlist:
66 list.append((x, self.lang[x]))
69 def getActiveLanguage(self):
70 return self.activeLanguage
72 def getActiveLanguageIndex(self):
73 for count in range(len(self.langlist)):
74 if self.langlist[count] == self.activeLanguage:
78 def getLanguage(self):
80 return str(self.lang[self.activeLanguage][1]) + "_" + str(self.lang[self.activeLanguage][2])
84 def addCallback(self, callback):
85 self.callbacks.append(callback)
87 def precalcLanguageList(self):
88 # excuse me for those T1, T2 hacks please. The goal was to keep the language_cache.py as small as possible, *and*
89 # don't duplicate these strings.
90 T1 = _("Please use the UP and DOWN keys to select your language. Afterwards press the OK button.")
91 T2 = _("Language selection")
92 l = open("language_cache.py", "w")
93 print >>l, "# -*- coding: UTF-8 -*-"
94 print >>l, "LANG_TEXT = {"
95 for language in self.langlist:
96 self.activateLanguage(language)
97 print >>l, '"%s": {' % language
98 for name, lang, country in self.lang.values():
99 print >>l, '\t"%s_%s": "%s",' % (lang, country, _(name))
101 print >>l, '\t"T1": "%s",' % (_(T1))
102 print >>l, '\t"T2": "%s",' % (_(T2))
106 language = Language()