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/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; 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); + } } 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