allow custom localization in simplerss and add italian translation (thx spaeleus)
[enigma2-plugins.git] / simplerss / src / __init__.py
1 # -*- coding: utf-8 -*-
2
3 from Components.Language import language
4 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_LANGUAGE
5 from os import environ as os_environ
6 import gettext
7
8 def localeInit():
9     lang = language.getLanguage()[:2] # getLanguage returns e.g. "fi_FI" for "language_country"
10     os_environ["LANGUAGE"] = lang # Enigma doesn't set this (or LC_ALL, LC_MESSAGES, LANG). gettext needs it!
11     print "[SimpleRSS] set language to ", lang
12     gettext.bindtextdomain("SimpleRSS", resolveFilename(SCOPE_PLUGINS, "Extensions/SimpleRSS/locale"))
13
14 def _(txt):
15     t = gettext.dgettext("SimpleRSS", txt)
16     if t == txt:
17         print "[SimpleRSS] fallback to default translation for", txt
18         t = gettext.gettext(txt)
19     return t
20
21 localeInit()
22 language.addCallback(localeInit)
23