d6810165e9f58923b4746a491fd25bb8646e206a
[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                 self.langlist = []
12                 # FIXME make list dynamically
13                 # name, iso-639 language, iso-3166 country. Please don't mix language&country!
14                 self.addLanguage(_("English"), "en", "EN")
15                 self.addLanguage(_("Arabic"), "ar", "AE")
16                 self.addLanguage(_("Danish"), "da", "DK")
17                 self.addLanguage(_("Dutch"), "nl", "NL")
18                 self.addLanguage(_("German"), "de", "DE")
19                 self.addLanguage(_("Icelandic"), "is", "IS")
20                 self.addLanguage(_("Italian"), "it", "IT")
21                 self.addLanguage(_("Norwegian"), "no", "NO")
22                 self.addLanguage(_("Spanish"), "es", "ES")
23                 self.addLanguage(_("Swedish"), "sv", "SE")
24                 
25                 self.callbacks = []
26
27         def addLanguage(self, name, lang, country):
28                 try:
29                         self.lang[str(lang + "_" + country)] = ((_(name), gettext.translation('enigma2', resolveFilename(SCOPE_LANGUAGE, ""), languages=[lang]), lang, country))
30                         self.langlist.append(str(lang + "_" + country))
31                 except:
32                         print "Language " + str(name) + " not found"
33
34         def activateLanguage(self, index):
35                 try:
36                         print "Activating language " + str(self.lang[index][0])
37                         self.lang[index][1].install()
38                         self.activeLanguage = index
39                         for x in self.callbacks:
40                                 x()
41                 except:
42                         print "Selected language does not exist!"
43
44         def getLanguageList(self):
45                 list = []
46                 for x in self.langlist:
47                         list.append((x, self.lang[x]))
48                 return list
49         
50         def getActiveLanguage(self):
51                 return self.activeLanguage
52         
53         def getLanguage(self):
54                 return str(self.lang[self.activeLanguage][2]) + "_" + str(self.lang[self.activeLanguage][3])
55         
56         def addCallback(self, callback):
57                 self.callbacks.append(callback)
58                 
59 language = Language()