add hungarian language
[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(_("German"), "de", "DE")
16                 self.addLanguage(_("Arabic"), "ar", "AE")
17                 self.addLanguage(_("Catalan"), "ca", "AD")
18                 self.addLanguage(_("Croatian"), "hr", "HR")
19                 self.addLanguage(_("Czech"), "cs", "CZ")
20                 self.addLanguage(_("Danish"), "da", "DK")
21                 self.addLanguage(_("Dutch"), "nl", "NL")
22                 self.addLanguage(_("Finnish"), "fi", "FI")
23                 self.addLanguage(_("French"), "fr", "FR")
24                 self.addLanguage(_("Hungarian"), "hu", "HU")
25                 self.addLanguage(_("Icelandic"), "is", "IS")
26                 self.addLanguage(_("Italian"), "it", "IT")
27                 self.addLanguage(_("Norwegian"), "no", "NO")
28                 self.addLanguage(_("Spanish"), "es", "ES")
29                 self.addLanguage(_("Swedish"), "sv", "SE")
30                 self.addLanguage(_("Turkish"), "tr", "TR")
31                 
32                 self.callbacks = []
33
34         def addLanguage(self, name, lang, country):
35                 try:
36                         self.lang[str(lang + "_" + country)] = ((_(name), gettext.translation('enigma2', resolveFilename(SCOPE_LANGUAGE, ""), languages=[lang]), lang, country))
37                         self.langlist.append(str(lang + "_" + country))
38                 except:
39                         print "Language " + str(name) + " not found"
40
41         def activateLanguage(self, index):
42                 try:
43                         print "Activating language " + str(self.lang[index][0])
44                         self.lang[index][1].install()
45                         self.activeLanguage = index
46                         for x in self.callbacks:
47                                 x()
48                 except:
49                         print "Selected language does not exist!"
50
51         def getLanguageList(self):
52                 list = []
53                 for x in self.langlist:
54                         list.append((x, self.lang[x]))
55                 return list
56
57         def getActiveLanguage(self):
58                 return self.activeLanguage
59
60         def getLanguage(self):
61                 try:
62                         return str(self.lang[self.activeLanguage][2]) + "_" + str(self.lang[self.activeLanguage][3])
63                 except:
64                         return ''
65
66         def addCallback(self, callback):
67                 self.callbacks.append(callback)
68
69 language = Language()