- add support for custom localizations and german translation
authorDr.Best <dr_best@users.schwerkraft.elitedvb.net>
Tue, 18 May 2010 20:25:40 +0000 (20:25 +0000)
committerDr.Best <dr_best@users.schwerkraft.elitedvb.net>
Tue, 18 May 2010 20:25:40 +0000 (20:25 +0000)
- changed caption width for long city names

Thanks to mcfreis for this patch! :-)

configure.ac
weatherplugin/Makefile.am
weatherplugin/po/Makefile.am [new file with mode: 0644]
weatherplugin/po/WeatherPlugin.pot [new file with mode: 0644]
weatherplugin/po/de.po [new file with mode: 0644]
weatherplugin/src/__init__.py
weatherplugin/src/plugin.py
weatherplugin/src/setup.py

index fe6fc73..4ddb1b1 100644 (file)
@@ -344,6 +344,7 @@ vxdcontrol/src/data/Makefile
 
 weatherplugin/Makefile
 weatherplugin/meta/Makefile
+weatherplugin/po/Makefile
 weatherplugin/src/Makefile
 
 webcamviewer/Makefile
index ff1ac3d..2966ae1 100755 (executable)
@@ -1 +1 @@
-SUBDIRS = src meta
+SUBDIRS = po src meta
diff --git a/weatherplugin/po/Makefile.am b/weatherplugin/po/Makefile.am
new file mode 100644 (file)
index 0000000..9013003
--- /dev/null
@@ -0,0 +1,57 @@
+#
+# to use this for the localisation of other plugins,
+# just change the DOMAIN to the name of the Plugin.
+# It is assumed, that the domain ist the same as
+# the directory name of the plugin.
+#
+
+DOMAIN=WeatherPlugin
+installdir = /usr/lib/enigma2/python/Plugins/Extensions/$(DOMAIN)
+#GETTEXT=./pygettext.py
+GETTEXT=xgettext
+
+#MSGFMT = ./msgfmt.py
+MSGFMT = msgfmt
+
+LANGS := de
+LANGPO := $(foreach LANG, $(LANGS),$(LANG).po)
+LANGMO := $(foreach LANG, $(LANGS),$(LANG).mo)
+
+default: $(DOMAIN).pot $(LANGPO) merge $(LANGMO)
+       for lang in $(LANGS); do \
+               mkdir -p $$lang/LC_MESSAGES; \
+               cp $$lang.mo $$lang/LC_MESSAGES/$(DOMAIN).mo; \
+       done
+
+merge:
+       for lang in $(LANGS); do \
+               msgmerge --no-location -s -N -U $$lang.po $(DOMAIN).pot; \
+       done
+
+
+# the TRANSLATORS: allows putting translation comments before the to-be-translated line.
+$(DOMAIN).pot:
+       $(GETTEXT) -L python --add-comments="TRANSLATORS:" -d $(DOMAIN) -s -o $(DOMAIN).pot ../src/*.py
+       msguniq -o $(DOMAIN)uniq.pot $(DOMAIN).pot
+       $(RM) $(DOMAIN).pot
+       mv $(DOMAIN)uniq.pot $(DOMAIN).pot
+
+.PHONY: $(DOMAIN).pot
+
+
+%.mo: %.po
+       $(MSGFMT) -o $@ $<
+
+%.po:
+       msginit -l $@ -o $@ -i $(DOMAIN).pot --no-translator
+
+CLEANFILES = $(foreach LANG, $(LANGS),$(LANG).mo)
+
+clean-local:
+       $(RM) -r $(LANGS)
+
+install-data-am: default
+       for lang in $(LANGS); do \
+               mkdir -p $(DESTDIR)$(installdir)/locale/$$lang/LC_MESSAGES; \
+               cp $$lang.mo $(DESTDIR)$(installdir)/locale/$$lang/LC_MESSAGES/$(DOMAIN).mo; \
+       done
diff --git a/weatherplugin/po/WeatherPlugin.pot b/weatherplugin/po/WeatherPlugin.pot
new file mode 100644 (file)
index 0000000..bdb9e57
--- /dev/null
@@ -0,0 +1,80 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2010-05-15 23:35+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: ../src/setup.py:66
+msgid "Add"
+msgstr ""
+
+#: ../src/setup.py:171
+msgid "Cancel"
+msgstr ""
+
+#: ../src/setup.py:64
+msgid "City"
+msgstr ""
+
+#: ../src/setup.py:183
+msgid "City or Postal Code"
+msgstr ""
+
+#: ../src/plugin.py:203
+#, python-format
+msgid "Current: %s"
+msgstr ""
+
+#: ../src/setup.py:68 ../src/setup.py:173
+msgid "Delete"
+msgstr ""
+
+#: ../src/setup.py:67
+msgid "Edit"
+msgstr ""
+
+#: ../src/plugin.py:130
+msgid "Getting weather information..."
+msgstr ""
+
+#: ../src/setup.py:65 ../src/setup.py:184
+msgid "Language"
+msgstr ""
+
+#: ../src/plugin.py:134
+msgid ""
+"No locations defined...\n"
+"Press 'Menu' to do that."
+msgstr ""
+
+#: ../src/setup.py:172
+msgid "OK"
+msgstr ""
+
+#: ../src/setup.py:106 ../src/setup.py:207
+msgid "Really delete this WeatherPlugin Entry?"
+msgstr ""
+
+#: ../src/plugin.py:61
+msgid "Weather Plugin"
+msgstr ""
+
+#: ../src/setup.py:161
+msgid "WeatherPlugin: Edit Entry"
+msgstr ""
+
+#: ../src/setup.py:59
+msgid "WeatherPlugin: List of Entries"
+msgstr ""
diff --git a/weatherplugin/po/de.po b/weatherplugin/po/de.po
new file mode 100644 (file)
index 0000000..f8f8db5
--- /dev/null
@@ -0,0 +1,88 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: WeatherPlugin\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2010-05-15 11:38+0200\n"
+"PO-Revision-Date: 2010-05-15 16:42+0100\n"
+"Last-Translator: Björn Freise <mcfreis@gmx.net>\n"
+"Language-Team: Björn Freise <mcfreis@gmx.net>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Poedit-Language: German\n"
+"X-Poedit-Country: GERMANY\n"
+"X-Poedit-SourceCharset: utf-8\n"
+
+#: ../src/setup.py:66
+msgid "Add"
+msgstr "Hinzufügen"
+
+#: ../src/setup.py:171
+msgid "Cancel"
+msgstr "Abbrechen"
+
+#: ../src/setup.py:64
+msgid "City"
+msgstr "Ort"
+
+#: ../src/setup.py:183
+msgid "City or Postal Code"
+msgstr "Ort oder Postleitzahl"
+
+#: ../src/plugin.py:203
+#, python-format
+msgid "Current: %s"
+msgstr "Aktuell: %s"
+
+#: ../src/setup.py:68
+#: ../src/setup.py:173
+msgid "Delete"
+msgstr "Löschen"
+
+#: ../src/setup.py:67
+msgid "Edit"
+msgstr "Bearbeiten"
+
+#: ../src/plugin.py:130
+msgid "Getting weather information..."
+msgstr "Laden der Wetterinformationen..."
+
+#: ../src/setup.py:65
+#: ../src/setup.py:184
+msgid "Language"
+msgstr "Sprache"
+
+#: ../src/plugin.py:134
+msgid ""
+"No locations defined...\n"
+"Press 'Menu' to do that."
+msgstr ""
+"Keine Einträge vorhanden.\n"
+"Bitte 'Menu' drücken um einen Eintrag anzulegen."
+
+#: ../src/setup.py:172
+msgid "OK"
+msgstr "OK"
+
+#: ../src/setup.py:106
+#: ../src/setup.py:207
+msgid "Really delete this WeatherPlugin Entry?"
+msgstr "Soll der Eintrag wirklich gelöscht werden?"
+
+#: ../src/plugin.py:61
+msgid "Weather Plugin"
+msgstr "Wetterinformationen"
+
+#: ../src/setup.py:161
+msgid "WeatherPlugin: Edit Entry"
+msgstr "Wetterinformationen: Eintrag bearbeiten"
+
+#: ../src/setup.py:59
+msgid "WeatherPlugin: List of Entries"
+msgstr "Wetterinformationen: Liste der Einträge"
+
index e69de29..3c408a3 100644 (file)
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+from Components.Language import language
+from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_LANGUAGE
+import os,gettext
+
+def localeInit():
+       lang = language.getLanguage()[:2] # getLanguage returns e.g. "fi_FI" for "language_country"
+       os.environ["LANGUAGE"] = lang # Enigma doesn't set this (or LC_ALL, LC_MESSAGES, LANG). gettext needs it!
+       gettext.bindtextdomain("WeatherPlugin", resolveFilename(SCOPE_PLUGINS, "Extensions/WeatherPlugin/locale"))
+
+def _(txt):
+       t = gettext.dgettext("WeatherPlugin", txt)
+       if t == txt:
+               print "[WeatherPlugin] fallback to default translation for", txt
+               t = gettext.gettext(txt)
+       return t
+
+localeInit()
+language.addCallback(localeInit)
index ec17f26..6b78422 100644 (file)
@@ -18,6 +18,9 @@
 #  GNU General Public License for more details.
 #
 
+# for localized messages
+from . import _
+
 from Plugins.Plugin import PluginDescriptor
 from Screens.Screen import Screen
 from Components.ActionMap import ActionMap
@@ -58,36 +61,37 @@ def main(session,**kwargs):
        session.open(WeatherPlugin)
 
 def Plugins(**kwargs):
-       list = [PluginDescriptor(name="Weather Plugin", description=_("Weather Plugin"), where = [PluginDescriptor.WHERE_EXTENSIONSMENU], fnc=main)]
+       list = [PluginDescriptor(name=_("Weather Plugin"), description=_("Weather Plugin"), where = [PluginDescriptor.WHERE_EXTENSIONSMENU], fnc=main)]
        return list
 
 
 class WeatherPlugin(Screen):
 
        skin = """
-               <screen name="WeatherPlugin" position="center,center" size="664,170" title="Weather Plugin">
+               <screen name="WeatherPlugin" position="center,center" size="664,190" title="%s">
                        <widget render="Label" source="caption" position="10,20" zPosition="1" size="300,23" font="Regular;22" transparent="1"/>
                        <widget render="Label" source="currentTemp" position="10,45" zPosition="1" size="300,23" font="Regular;22" transparent="1"/>
-                       <widget render="Label" source="condition" position="10,80" zPosition="1" size="300,20" font="Regular;18" transparent="1"/>
-                       <widget render="Label" source="wind_condition" position="10,105" zPosition="1" size="300,20" font="Regular;18" transparent="1"/>
-                       <widget render="Label" source="humidity" position="10,130" zPosition="1" size="300,20" font="Regular;18" valign="bottom" transparent="1"/>
-                       <widget render="Label" source="weekday1" position="255,30" zPosition="1" size="72,20" halign="center" valign="center" font="Regular;18" transparent="1"/>
-                       <widget name="weekday1_icon" position="255,50" zPosition="1" size="72,72" alphatest="blend"/>
-                       <widget render="Label" source="weekday1_temp" position="241,130" zPosition="1" size="100,20" halign="center" valign="bottom" font="Regular;16" transparent="1"/>
-                       <widget render="Label" source="weekday2" position="358,30" zPosition="1" size="72,20" halign="center" valign="center" font="Regular;18" transparent="1"/>
-                       <widget name="weekday2_icon" position="358,50" zPosition="1" size="72,72" alphatest="blend"/>
-                       <widget render="Label" source="weekday2_temp" position="344,130" zPosition="1" size="100,20" halign="center" valign="bottom" font="Regular;16" transparent="1"/>
-                       <widget render="Label" source="weekday3" position="461,30" zPosition="1" size="72,20" halign="center" valign="center" font="Regular;18" transparent="1"/>
-                       <widget name="weekday3_icon" position="461,50" zPosition="1" size="72,72" alphatest="blend"/>
-                       <widget render="Label" source="weekday3_temp" position="448,130" zPosition="1" size="100,20" halign="center" valign="bottom" font="Regular;16" transparent="1"/>
-                       <widget render="Label" source="weekday4" position="564,30" zPosition="1" size="72,20" halign="center" valign="center" font="Regular;18" transparent="1"/>
-                       <widget name="weekday4_icon" position="564,50" zPosition="1" size="72,72" alphatest="blend"/>
-                       <widget render="Label" source="weekday4_temp" position="550,130" zPosition="1" size="100,20" halign="center" valign="bottom" font="Regular;16" transparent="1"/>
-                       <widget render="Label" source="statustext" position="0,0" zPosition="1" size="664,170" font="Regular;20" halign="center" valign="center" transparent="1"/>
-               </screen>"""
+                       <widget render="Label" source="condition" position="10,100" zPosition="1" size="300,20" font="Regular;18" transparent="1"/>
+                       <widget render="Label" source="wind_condition" position="10,125" zPosition="1" size="300,20" font="Regular;18" transparent="1"/>
+                       <widget render="Label" source="humidity" position="10,150" zPosition="1" size="300,20" font="Regular;18" valign="bottom" transparent="1"/>
+                       <widget render="Label" source="weekday1" position="255,50" zPosition="1" size="72,20" halign="center" valign="center" font="Regular;18" transparent="1"/>
+                       <widget name="weekday1_icon" position="255,70" zPosition="1" size="72,72" alphatest="blend"/>
+                       <widget render="Label" source="weekday1_temp" position="241,150" zPosition="1" size="100,20" halign="center" valign="bottom" font="Regular;16" transparent="1"/>
+                       <widget render="Label" source="weekday2" position="358,50" zPosition="1" size="72,20" halign="center" valign="center" font="Regular;18" transparent="1"/>
+                       <widget name="weekday2_icon" position="358,70" zPosition="1" size="72,72" alphatest="blend"/>
+                       <widget render="Label" source="weekday2_temp" position="344,150" zPosition="1" size="100,20" halign="center" valign="bottom" font="Regular;16" transparent="1"/>
+                       <widget render="Label" source="weekday3" position="461,50" zPosition="1" size="72,20" halign="center" valign="center" font="Regular;18" transparent="1"/>
+                       <widget name="weekday3_icon" position="461,70" zPosition="1" size="72,72" alphatest="blend"/>
+                       <widget render="Label" source="weekday3_temp" position="448,150" zPosition="1" size="100,20" halign="center" valign="bottom" font="Regular;16" transparent="1"/>
+                       <widget render="Label" source="weekday4" position="564,50" zPosition="1" size="72,20" halign="center" valign="center" font="Regular;18" transparent="1"/>
+                       <widget name="weekday4_icon" position="564,70" zPosition="1" size="72,72" alphatest="blend"/>
+                       <widget render="Label" source="weekday4_temp" position="550,150" zPosition="1" size="100,20" halign="center" valign="bottom" font="Regular;16" transparent="1"/>
+                       <widget render="Label" source="statustext" position="0,0" zPosition="1" size="664,190" font="Regular;20" halign="center" valign="center" transparent="1"/>
+               </screen>""" %  _("Weather Plugin")
        
        def __init__(self, session):
                Screen.__init__(self, session)
+
                self["actions"] = ActionMap(["WizardActions", "DirectionActions", "ColorActions", "EPGSelectActions"],
                {
                        "back": self.close,
index 65f6006..faf6239 100644 (file)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 #
 #  Weather Plugin E2
 #
@@ -17,6 +18,9 @@
 #  GNU General Public License for more details.
 #
 
+# for localized messages
+from . import _
+
 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT, \
        RT_VALIGN_CENTER
 from Screens.Screen import Screen
@@ -154,11 +158,10 @@ class WeatherPluginEntryConfigScreen(ConfigListScreen, Screen):
                        <widget source="key_red" render="Label" position="0,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
                        <widget source="key_green" render="Label" position="140,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
                        <widget source="key_blue" render="Label" position="420,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
-               </screen>"""
+               </screen>""" % _("WeatherPlugin: Edit Entry")
 
        def __init__(self, session, entry):
                Screen.__init__(self, session)
-               self.title = _("WeatherPlugin: Edit Entry")
 
                self["actions"] = ActionMap(["SetupActions", "ColorActions"],
                {