- switchtimer added to RecordingTimer
[openblackhole/openblackhole-enigma2.git] / lib / python / Components / Language.py
1 import gettext
2 import os
3
4 from Tools.Directories import *
5
6 class Language:
7         def __init__(self):
8                 gettext.install('enigma2', resolveFilename(SCOPE_LANGUAGE, ""), unicode=0, codeset="utf-8")
9                 self.activeLanguage = 0
10                 self.lang = {}
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(_("Dutch"), "nl", "NL")
17                 self.addLanguage(_("Spanish"), "es", "ES")
18                 self.addLanguage(_("Icelandic"), "is", "IS")
19                 
20                 self.callbacks = []
21
22         def addLanguage(self, name, lang, country):
23                 #try:
24                         self.lang[str(lang + "_" + country)] = ((_(name), gettext.translation('enigma2', resolveFilename(SCOPE_LANGUAGE, ""), languages=[lang]), lang, country))
25                 #except:
26                 #       print "Language " + str(name) + " not found"
27
28         def activateLanguage(self, index):
29                 try:
30                         print "Activating language " + str(self.lang[index][0])
31                         self.lang[index][1].install()
32                         self.activeLanguage = index
33                         for x in self.callbacks:
34                                 x()
35                 except:
36                         print "Selected language does not exist!"
37
38         def getLanguageList(self):
39                 list = []
40                 for x in self.lang.keys():
41                         list.append((x, self.lang[x]))
42                 return list
43         
44         def getActiveLanguage(self):
45                 return self.activeLanguage
46         
47         def getLanguage(self):
48                 return str(self.lang[self.activeLanguage][2]) + "_" + str(self.lang[self.activeLanguage][3])
49         
50         def addCallback(self, callback):
51                 self.callbacks.append(callback)
52                 
53 language = Language()