kmpoppe / noteSolver

JOSM Plugin: Automatically resolve notes after uploading a changeset.
https://wiki.openstreetmap.org/wiki/User:Kmpoppe/Plugins#noteSolver
GNU General Public License v3.0
12 stars 3 forks source link

Use I18n #6

Closed simon04 closed 2 years ago

simon04 commented 4 years ago

Please use @JOSM's class I18n for internationalization support, for instance:

diff --git a/notesolver/src/org/openstreetmap/josm/plugins/notesolver/NoteSolverPlugin.java b/notesolver/src/org/openstreetmap/josm/plugins/notesolver/NoteSolverPlugin.java
index 13b8a40..a85d750 100644
--- a/notesolver/src/org/openstreetmap/josm/plugins/notesolver/NoteSolverPlugin.java
+++ b/notesolver/src/org/openstreetmap/josm/plugins/notesolver/NoteSolverPlugin.java
@@ -20,6 +20,7 @@ import org.openstreetmap.josm.gui.progress.ProgressMonitor;

 import org.openstreetmap.josm.plugins.*;
 import org.openstreetmap.josm.spi.preferences.Config;
+import org.openstreetmap.josm.tools.I18n;

 import java.awt.event.*;
 import java.awt.*;
@@ -74,8 +75,8 @@ public class NoteSolverPlugin extends Plugin {

                                int outVal = JOptionPane.showConfirmDialog(
                                        null,
-                                       "Automatically Resolve Note" + (rememberedNotes.size() > 1 ? "s" : "") + crLf + noteList + crLf + "?", 
+                                       I18n.trn("Automatically Resolve Note\n{0}?", "Automatically Resolve Notes\n{0}\n?", rememberedNotes.size(), noteList),
                                        null, 
                                        JOptionPane.YES_NO_CANCEL_OPTION, 
                                        JOptionPane.QUESTION_MESSAGE
                                );
@@ -86,14 +87,14 @@ public class NoteSolverPlugin extends Plugin {
                                        if (autoUploadDecision) {
                                                String comment = MainApplication.getLayerManager().getEditDataSet().getChangeSetTags().get("comment");
                                                for (Note note : solvedNotes) {
-                                                       String noteLink = "Closes " + getUrl(note, linkTypes.NOTE);
+                                                       String noteLink = I18n.tr("Closes {0}", getUrl(note, linkTypes.NOTE));
                                                        if (comment != null) {
                                                                comment = comment.replace("; " + noteLink, "");
                                                                comment = comment.replace(noteLink, "");
                                                        }
                                                }
                                                for (Note note : rememberedNotes) {
-                                                       String noteLink = "Closes " + getUrl(note, linkTypes.NOTE);
+                                                       String noteLink = I18n.tr("Closes {0}", getUrl(note, linkTypes.NOTE));
                                                        comment = (comment != null ? (comment.contains(noteLink) ? comment : comment + "; " + noteLink) : noteLink);
                                                }
                                                MainApplication.getLayerManager().getEditDataSet().addChangeSetTag("comment", comment);
kmpoppe commented 4 years ago

@simon04 Do you read the josm-dev list? Can you help me create the .pot and .lang files using ant? I seem to be missing pieces of the puzzle...

floscher commented 3 years ago

I'm not really familiar with how this is done with Ant on GitHub.

In #12 there is a simple shell script that could extract a *.pot file from the sources.

I believe the precondition to using Launchpad translation is to have your plugin added as svn:external here: https://josm.openstreetmap.de/browser/osm/applications/editors/josm/plugins And I think the precondition for that is to transfer your plugin into the JOSM group on GitHub. Then the *.pot file would be automatically be uploaded to Launchpad and the JOSM maintainers would update the *.lang files. That process uses some perl scripts located here: https://josm.openstreetmap.de/browser/osm/applications/editors/josm/i18n

For my projects I'm usually using the gradle-josm-plugin, which can generate the *.pot file and later generate *.lang files from *.po files, regardless where the JOSM plugin is hosted.

kmpoppe commented 2 years ago

@floscher I've merged your #13 - thank you, that makes building the plugin so much easier. Alas, I managed to get a .pot (generatePot) and build myself a de.po using POEdit, but how do I get on from there? I thought that compilePo was the next step, but I don't seem to get where I have to place them for creating a .lang. Could you enlightend me?

floscher commented 2 years ago

@kmpoppe When you put the translated .po files in a new src/main/po directory, they should be picked up automatically. The compilePo task will be executed when needed, so you don't have to call that explicitly. Just do e.g. ./gradlew dist and the built .jar file should contain the translations.

kmpoppe commented 2 years ago

@floscher Thanks! Things I learned: I need to give it a specific English translation file, otherwise JOSM will pick the only other avaiable translation. Welp ;-) Does runJosm force it to be English? I have changed the settings to use German (de) - which also gets saved in the properties correctly - but the UI is still English ... or is this just unfortunate timing because josm.openstreetmap.de is currently broken?

floscher commented 2 years ago

@kmpoppe Can you explain the problem, that you need an English translation file, in a bit more detail? Normally an en.po file should not be needed. This might be a bug with the gradle-josm-plugin, if you indeed have to create an en.po file to get it to work. Maybe you could open an issue on GitLab or GitHub for that.

The issue with runJosm always using English texts is a known problem. I'm not really sure what causes this, but somehow JOSM can't read the translations from JOSM core, but only the translations for your plugin. So everything is in English, except the strings that are in the *.po files for your plugin. But this is only a problem when starting through runJosm, when the plugin is installed normally to JOSM, everything should work fine.

floscher commented 2 years ago

@kmpoppe Ah, I think I know what went wrong. The .po files need to be named just with the language abbreviation, so just name it de.po, the same as the .lang files are named.

kmpoppe commented 2 years ago

@floscher Yeah, i figured, after seeing a .lang file in the .jar, that this should be the case. Alas, the file names are the direct export of poeditor.com, so I'll just have to rename them here in the repo.