from Components.Language import language
from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_LANGUAGE

import os, gettext

PluginLanguageDomain = "CrossEPG"
PluginLanguagePath = "SystemPlugins/CrossEPG/po"

def localeInit():
	if os.path.exists(resolveFilename(SCOPE_PLUGINS, os.path.join(PluginLanguagePath, language.getLanguage()))):
		lang = language.getLanguage()
	else:
		lang = language.getLanguage()[:2]
	os.environ["LANGUAGE"] = lang # Enigma doesn't set this (or LC_ALL, LC_MESSAGES, LANG). gettext needs it!
	print "[CrossEPG] set language to ", lang
	gettext.bindtextdomain(PluginLanguageDomain, resolveFilename(SCOPE_PLUGINS, PluginLanguagePath))
	gettext.bindtextdomain('enigma2', resolveFilename(SCOPE_LANGUAGE, ""))

def _(txt):
	t = gettext.dgettext(PluginLanguageDomain, txt)
	if t == txt:
		#print "[CrossEPG] fallback to default translation for", txt
		t = gettext.dgettext('enigma2', txt)
	return t


localeInit()
language.addCallback(localeInit)

@@ -1,12 +1,36 @@
+# -*- coding: utf-8 -*-%0A
 from Compone
@@ -135,17 +135,16 @@
 ANGUAGE%0A
-%0A
 import o
@@ -553,51 +553,8 @@
 it!%0A
-%09print %22%5BCrossEPG%5D set language to %22, lang%0A
 %09get
@@ -650,80 +650,8 @@
 th))
-%0A%09gettext.bindtextdomain('enigma2', resolveFilename(SCOPE_LANGUAGE, %22%22))
 %0A%0Ade
@@ -729,17 +729,16 @@
 :%0A%09%09
-#
 print %22%5B
 Cros
@@ -733,24 +733,44 @@
 print %22%5B
-CrossEPG
+%22 + PluginLanguageDomain + %22
 %5D fallba
@@ -819,25 +819,24 @@
 gettext.
-d
 gettext(
 'enigma2
@@ -831,19 +831,8 @@
 ext(
-'enigma2', 
 txt)
@@ -843,17 +843,16 @@
 turn t%0A%0A
-%0A
 localeIn

update code.