translation: don't fail when no language exists
[enigma2.git] / lib / python / Components / Language.py
1 import gettext
2 import os
3
4 class Language:
5         def __init__(self):
6                 gettext.install('enigma2', '/enigma2/po')
7                 self.lang = []
8                 # FIXME make list dynamically
9                 self.addLanguage(_("English"), "en")
10                 self.addLanguage(_("German"), "de")
11
12         def addLanguage(self, name, lang):
13                 try:
14                         self.lang.append((_(name), gettext.translation('enigma2', '/enigma2/po', languages=[lang])))
15                 except:
16                         print "Language " + str(name) + " not found"
17
18         def activateLanguage(self, index):
19                 try:
20                         print "Activating language " + str(self.lang[index][0])
21                         self.lang[index][1].install()
22                 except:
23                         print "Selected language does not exist!"
24                 
25         def getLanguageList(self):
26                 list = []
27                 for x in self.lang:
28                         list.append(x[0])
29                 return list
30
31 language = Language()