Hi,

I made a patch to support I18N for plugin descriptions. This would be a
first step for bug #762.

At this point the translation is supported, if the description is read
from the jar file. The translated descriptions will go to the plugins
build.xml file like the original description. As an example I have
attached a patch to the build.xml for the slippy_map_chooser plugin. For
the different languages the language code plus an underscore is set in
front of the Plugin-Description attribute. So for German it will be
de_Plugin-Description. A full language code like de_ch for Swiss German
is also supported.

What is missing for now is I18N support, if the descriptions are loaded
down from the web. For this I think it would be the best, that JOSM will
request http://josm.openstreetmap.de/wiki/Plugins/de or
http://josm.openstreetmap.de/wiki/DE:Plugins and if the Wiki has no such
page it will return the default
http://josm.openstreetmap.de/wiki/Plugins page. I don't know it
something like this is possible with trac.

Cheers, detlef
--- josm-svn/plugins/slippy_map_chooser/build.xml	2009-01-19 01:38:01.000000000 +0100
+++ josm-dev/plugins/slippy_map_chooser/build.xml	2009-01-21 19:14:50.000000000 +0100
@@ -31,6 +31,7 @@
             <manifest>
                 <attribute name="Plugin-Class" value="SlippyMapChooserPlugin" />
                 <attribute name="Plugin-Description" value="Adds a new download dialog that allows to select the download rectangle on the slippy map. With this plugin it's possible to download ways and gpx logs without knowing the coordinates of the desired download rectangle - just navigate to the desired area by zooming and moving the slippy map, mark the area with a rectangle and click download. Works great together with the namefinder plugin!" />
+                <attribute name="de_Plugin-Description" value="Fügt einen weiteren Download-Dialog hinzu, um einen Bereich auf der schnellen Karte auszuwählen. Mit diesem Plugin ist es möglich Wege und GPX-Logs herunter zu laden, ohne die Koordinaten des Download-Bereichs zu kennen - navigiere einfach durch Zoomen und verschieben der Schnellen Karte zum gewünschten Bereich, markiere den Bereich mt einem Rechteck und klicke Herunterladen. Arbeitet sehr gut mit dem namefinder Plugin zusammen." />
                 <attribute name="Plugin-Author" value="[email protected]" />
                 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
                 <attribute name="Plugin-Date" value="${version.entry.commit.date}"/>
diff -urb --exclude='*.svn*' --exclude='*.jar' --exclude=build josm-svn/core/src/org/openstreetmap/josm/plugins/PluginInformation.java josm-dev/core/src/org/openstreetmap/josm/plugins/PluginInformation.java
--- josm-svn/core/src/org/openstreetmap/josm/plugins/PluginInformation.java	2009-01-19 01:39:28.000000000 +0100
+++ josm-dev/core/src/org/openstreetmap/josm/plugins/PluginInformation.java	2009-01-21 19:17:59.000000000 +0100
@@ -13,6 +13,7 @@
 import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.TreeMap;
 import java.util.jar.Attributes;
@@ -58,6 +59,26 @@
         this(file, file.getName().substring(0, file.getName().length()-4), null);
     }
 
+    private String getLocalizedPluginDescription(Attributes attr, String key) {
+        String loc = Locale.getDefault().toString();
+        String val = null;        
+
+        try {
+            val = attr.getValue(loc + "_" + key);
+        } catch (IllegalArgumentException ex) {}
+        if (val != null)
+            return val;
+
+        String lang = loc.split ("_", 2)[0];
+        try {
+        val = attr.getValue(lang + "_" + key);
+        } catch (IllegalArgumentException ex) {}
+        if (val != null)
+            return val;
+
+        return (attr.getValue(key));
+    }
+
     public PluginInformation(File file, String name, InputStream manifestStream) {
         this.name = name;
         this.file = file;
@@ -76,7 +97,7 @@
             if (manifest != null) {
                 Attributes attr = manifest.getMainAttributes();
                 className = attr.getValue("Plugin-Class");
-                description = attr.getValue("Plugin-Description");
+                description = getLocalizedPluginDescription(attr, "Plugin-Description");
                 early = Boolean.parseBoolean(attr.getValue("Plugin-Early"));
                 String stageStr = attr.getValue("Plugin-Stage");
                 stage = stageStr == null ? 50 : Integer.parseInt(stageStr);
_______________________________________________
josm-dev mailing list
[email protected]
http://lists.openstreetmap.org/listinfo/josm-dev

Reply via email to