Added: commandDescriptionKey to @Parameters, to allow internationalized command descriptions
diff --git a/CHANGELOG b/CHANGELOG
index cf51a4f..1e3d872 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,7 @@
Current
+Added: commandDescriptionKey to @Parameters, to allow internationalized command descriptions
Fixed: GITHUB-73: descriptionKey was being ignored on main parameters
1.18
diff --git a/src/main/java/com/beust/jcommander/JCommander.java b/src/main/java/com/beust/jcommander/JCommander.java
index cd5325e..3308880 100644
--- a/src/main/java/com/beust/jcommander/JCommander.java
+++ b/src/main/java/com/beust/jcommander/JCommander.java
@@ -766,12 +766,21 @@
Parameters p = jc.getObjects().get(0).getClass().getAnnotation(Parameters.class);
String result = jc.getMainParameterDescription();
- if (p != null) result = p.commandDescription();
+ if (p != null) result = getI18nString(p.commandDescriptionKey(), p.commandDescription());
return result;
}
/**
+ * @return The internationalized version of the string if available, otherwise
+ * return def.
+ */
+ private String getI18nString(String key, String def) {
+ String s = m_bundle != null ? m_bundle.getString(key) : null;
+ return s != null ? s : def;
+ }
+
+ /**
* Display a the help on System.out.
*/
public void usage() {
diff --git a/src/main/java/com/beust/jcommander/Parameters.java b/src/main/java/com/beust/jcommander/Parameters.java
index cffc030..e25d1f2 100644
--- a/src/main/java/com/beust/jcommander/Parameters.java
+++ b/src/main/java/com/beust/jcommander/Parameters.java
@@ -55,4 +55,9 @@
* description when @{link JCommander#usage} is invoked.
*/
String commandDescription() default "";
+
+ /**
+ * @return the key used to find the command description in the resource bundle.
+ */
+ String commandDescriptionKey() default "";
}