Repository navigation
i18n
h908714124 edited this page Aug 13, 2026
·
7 revisions
In order to do i18n of your command line interface, you need a Map<String, String> containing message keys and the corresponding translations.
If you have a ResourceBundle, you have to convert it to a map first:
private static Map<String, String> toMap(ResourceBundle bundle) {
return Collections.list(bundle.getKeys()).stream()
.collect(Collectors.toMap(Function.identity(), bundle::getString));
}Call the withMessages(Map<String, String>) method on the generated parser as follows:
public static void main(String[] args) {
Map<String, String> messages = Map.of("key.apple", "manzana");
int rc = DeleteCommandParser.parse(List.of(args)).fold(
failure -> {
StandardErrorHandler.builder()
.withMessages(messages)
.build()
.printErrorMessage(failure);
System.exit(1);
return 1;
},
command -> {
// some cool stuff...
return 0;
}
);
System.exit(rc);
}In the command interface, use the descriptionKey attribute to register a i18n key:
@Option(names = "--gateway-host",
description = "apple",
descriptionKey = "key.apple")
String gatewayHost();