From 8a250ca8e187c45873df9299c55a03838d6e58b3 Mon Sep 17 00:00:00 2001 From: Sebastian Annies Date: Mon, 17 Aug 2015 09:44:07 +0200 Subject: [PATCH 1/3] show problem with test --- .../test/org/kohsuke/args4j/ArgumentTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/args4j/test/org/kohsuke/args4j/ArgumentTest.java b/args4j/test/org/kohsuke/args4j/ArgumentTest.java index fffcea1a..0302b046 100644 --- a/args4j/test/org/kohsuke/args4j/ArgumentTest.java +++ b/args4j/test/org/kohsuke/args4j/ArgumentTest.java @@ -2,7 +2,10 @@ import junit.framework.TestCase; +import java.io.File; +import java.io.StringWriter; import java.util.List; +import java.util.ResourceBundle; public class ArgumentTest extends TestCase { protected static class MultiValueHolder { @@ -20,6 +23,14 @@ protected static class BooleanValueHolder { public boolean b; } + protected static class I18NValueHolder { + @Argument(usage = "FILE2READ", required = true) + public File b; + + @Option(name = "-a", usage = "1 2 3") + public String opt; + } + public void testMultiValue() throws Exception { MultiValueHolder holder = new MultiValueHolder(); CmdLineParser parser = new CmdLineParser(holder); @@ -64,4 +75,13 @@ public void testIllegalBoolean() throws Exception { } fail("expected " + CmdLineException.class); } + + public void testI18N() { + I18NValueHolder holder = new I18NValueHolder(); + CmdLineParser parser = new CmdLineParser(holder); + StringWriter sw = new StringWriter(); + ResourceBundle rb = ResourceBundle.getBundle("org/kohsuke/args4j/ArgumentTestI18N"); + parser.printUsage(sw, rb); + assertTrue(sw.toString()!=null); + } } From 0b63e00e22956da990f02c5a19423aa2b8e760f9 Mon Sep 17 00:00:00 2001 From: Sebastian Annies Date: Mon, 17 Aug 2015 09:48:36 +0200 Subject: [PATCH 2/3] fixing missing localization problem for options and arguments --- args4j/src/org/kohsuke/args4j/CmdLineParser.java | 4 +++- args4j/src/org/kohsuke/args4j/spi/OptionHandler.java | 6 ++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/args4j/src/org/kohsuke/args4j/CmdLineParser.java b/args4j/src/org/kohsuke/args4j/CmdLineParser.java index c387b119..f22ddd0b 100644 --- a/args4j/src/org/kohsuke/args4j/CmdLineParser.java +++ b/args4j/src/org/kohsuke/args4j/CmdLineParser.java @@ -366,7 +366,9 @@ private String createDefaultValuePart(OptionHandler handler) { } private String localize(String s, ResourceBundle rb) { - if(rb!=null) return rb.getString(s); + if(rb!=null && rb.containsKey(s)) { + return rb.getString(s); + } return s; } diff --git a/args4j/src/org/kohsuke/args4j/spi/OptionHandler.java b/args4j/src/org/kohsuke/args4j/spi/OptionHandler.java index cb1f0095..faeb17af 100644 --- a/args4j/src/org/kohsuke/args4j/spi/OptionHandler.java +++ b/args4j/src/org/kohsuke/args4j/spi/OptionHandler.java @@ -82,10 +82,8 @@ public String getMetaVariable(ResourceBundle rb) { token = getDefaultMetaVariable(); if(token==null) return null; - if(rb!=null) { - String localized = rb.getString(token); - if(localized!=null) - token = localized; + if(rb!=null && rb.containsKey(token)) { + token = rb.getString(token); } return token; From aab477e35cf33ce8cb25b4ad96fe9f83a30d3d87 Mon Sep 17 00:00:00 2001 From: Sebastian Annies Date: Mon, 17 Aug 2015 11:35:41 +0200 Subject: [PATCH 3/3] resource was missing --- args4j/pom.xml | 1 + args4j/test/org/kohsuke/args4j/ArgumentTestI18N.properties | 1 + 2 files changed, 2 insertions(+) create mode 100644 args4j/test/org/kohsuke/args4j/ArgumentTestI18N.properties diff --git a/args4j/pom.xml b/args4j/pom.xml index 9f1a48ec..bd65cc14 100644 --- a/args4j/pom.xml +++ b/args4j/pom.xml @@ -28,6 +28,7 @@ test **/*.xml + **/*.properties diff --git a/args4j/test/org/kohsuke/args4j/ArgumentTestI18N.properties b/args4j/test/org/kohsuke/args4j/ArgumentTestI18N.properties new file mode 100644 index 00000000..3ec4ac3c --- /dev/null +++ b/args4j/test/org/kohsuke/args4j/ArgumentTestI18N.properties @@ -0,0 +1 @@ +FILE2READ=File to read \ No newline at end of file