version 1.1.1
[enigma2-curlytx.git] / src / __init__.py
1 # -*- coding: utf-8 -*-
2 # CurlyTx translation initialization
3 # Copyright (C) 2011 Christian Weiske <cweiske@cweiske.de>
4 # License: GPLv3 or later
5
6 from Components.Language import language
7 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_LANGUAGE
8 from os import environ as os_environ
9 import gettext
10
11 def localeInit():
12     """ Prepare settings for gettext usage """
13     lang = language.getLanguage()[:2] # getLanguage returns e.g. "fi_FI" for "language_country"
14     os_environ["LANGUAGE"] = lang # Enigma doesn't set this (or LC_ALL, LC_MESSAGES, LANG). gettext needs it!
15     gettext.bindtextdomain("CurlyTx", resolveFilename(SCOPE_PLUGINS, "Extensions/CurlyTx/locale"))
16
17 def _(txt):
18     """ Custom gettext translation function that uses the CurlyTx domain """
19     t = gettext.dgettext("CurlyTx", txt)
20     if t == txt:
21         #print "[CurlyTx] fallback to default translation for", txt
22         t = gettext.gettext(txt)
23     return t
24
25 localeInit()
26 language.addCallback(localeInit)