-
Notifications
You must be signed in to change notification settings - Fork 418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Localisation of phrase "Default" #605
Comments
You should be able to accomplish this with the current version of picocli by embedding the
I believe this should also work when the description text is coming from a resource bundle. (This gives more flexibility, so you can use other text than |
I confirmed this works: package test;
import static org.junit.Assert.*;
import org.junit.Test;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Vector;
public class I18nTest {
@Test
public void testI18nDemo() {
CommandLine commandLine = new CommandLine(new I18nDemo());
String actual = commandLine.getUsageMessage();
String expected = String.format("" +
"Usage: i18n [-x=<x>] [-y=<y>]%n" +
"bundle text%n" +
" -x=<x> 日本語 34 for x%n" +
" -y=<y> 日本語 4444 for y%n");
assertEquals(expected, actual);
}
@Command(name="i18n", resourceBundle = "test.I18nTest$MyBundle")
static class I18nDemo {
@CommandLine.Option(names = "-x", defaultValue = "34") int x;
@CommandLine.Option(names = "-y") int y = 4444;
}
public static class MyBundle extends ResourceBundle {
Map<String, String> map = new HashMap<String, String>();
public MyBundle() {
map.put("usage.description", "bundle text");
map.put("x", "日本語 ${DEFAULT-VALUE} for x");
map.put("y", "日本語 ${DEFAULT-VALUE} for y");
}
protected Object handleGetObject(String s) {
return map.get(s);
}
public Enumeration<String> getKeys() {
return new Vector<String>(map.keySet()).elements();
}
}
} |
Yes, I can confirm that this works, and this is a valid solution for sure. Everything looks great now in my use case, except for one minor issue. I'm using:
Requesting help for the parent command results in
Is there any easy way to localize the description for the 'help' subcommand ('Displays help information about the specified command')? Thanks for you answer! |
I think you can override by providing entries in your resource bundle:
|
No, that didn't do the trick for me. |
Ok, I’ll try to test this tomorrow. Is the spelling of the key correct? Should it be capitalized “Parent” for your application? |
Localizing the built-in help subcommand I found it. The resource bundle keys for the built-in
|
About using Going forward I plan to add more variables like this. (If I had thought of the variables first I would not have provided the |
The I18nTest has examples of localizing the built-in help command. |
I will update the Internationalization section of the user manual to clarify:
|
Yes indeed, that's helpful. Since this file is not obvious to novice users, it would be even better to have a fully working example in the 'examples' section. I'm willing to contribute, if you don't mind. Two questions:
|
That would be great, thank you! |
@deining, how is it going? Let me know if you need any help. |
I added an extra test and updated the Internationalization section of the user manual. |
Thanks for your efforts, everything is fine for me now. |
If you don't mind I will close this ticket. |
I have a simple command with showDefaultValues=true:
Is there a simple way to localize the phrase 'Default' via an entry in the resource bundle so that the output with German locale looks like this?
Thanks for your support.
The text was updated successfully, but these errors were encountered: