fix imports
[enigma2.git] / lib / python / Components / Language.py
1 import gettext
2
3 from Tools.Directories import SCOPE_LANGUAGE, resolveFilename
4
5 class Language:
6         def __init__(self):
7                 gettext.install('enigma2', resolveFilename(SCOPE_LANGUAGE, ""), unicode=0, codeset="utf-8")
8                 self.activeLanguage = 0
9                 self.lang = {}
10                 self.langlist = []
11                 # FIXME make list dynamically
12                 # name, iso-639 language, iso-3166 country. Please don't mix language&country!
13                 self.addLanguage(_("English"), "en", "EN")
14                 self.addLanguage(_("German"), "de", "DE")
15                 self.addLanguage(_("Arabic"), "ar", "AE")
16                 self.addLanguage(_("Catalan"), "ca", "AD")
17                 self.addLanguage(_("Croatian"), "hr", "HR")
18                 self.addLanguage(_("Czech"), "cs", "CZ")
19                 self.addLanguage(_("Danish"), "da", "DK")
20                 self.addLanguage(_("Dutch"), "nl", "NL")
21                 self.addLanguage(_("Finnish"), "fi", "FI")
22                 self.addLanguage(_("French"), "fr", "FR")
23                 self.addLanguage(_("Hungarian"), "hu", "HU")
24                 self.addLanguage(_("Icelandic"), "is", "IS")
25                 self.addLanguage(_("Italian"), "it", "IT")
26                 self.addLanguage(_("Norwegian"), "no", "NO")
27                 self.addLanguage(_("Spanish"), "es", "ES")
28                 self.addLanguage(_("Swedish"), "sv", "SE")
29                 self.addLanguage(_("Turkish"), "tr", "TR")
30                 
31                 self.callbacks = []
32
33         def addLanguage(self, name, lang, country):
34                 try:
35                         self.lang[str(lang + "_" + country)] = ((_(name), gettext.translation('enigma2', resolveFilename(SCOPE_LANGUAGE, ""), languages=[lang]), lang, country))
36                         self.langlist.append(str(lang + "_" + country))
37                 except:
38                         print "Language " + str(name) + " not found"
39
40         def activateLanguage(self, index):
41                 try:
42                         print "Activating language " + str(self.lang[index][0])
43                         self.lang[index][1].install()
44                         self.activeLanguage = index
45                         for x in self.callbacks:
46                                 x()
47                 except:
48                         print "Selected language does not exist!"
49
50         def getLanguageList(self):
51                 list = []
52                 for x in self.langlist:
53                         list.append((x, self.lang[x]))
54                 return list
55
56         def getActiveLanguage(self):
57                 return self.activeLanguage
58
59         def getLanguage(self):
60                 try:
61                         return str(self.lang[self.activeLanguage][2]) + "_" + str(self.lang[self.activeLanguage][3])
62                 except:
63                         return ''
64
65         def addCallback(self, callback):
66                 self.callbacks.append(callback)
67
68 language = Language()