There was an error while loading. Please reload this page.
In order to do internationalization, you need a Map<String, String> containing message keys and the corresponding translations.
Map<String, String>
If you have a ResourceBundle, you have to convert it to a map first:
ResourceBundle
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:
withMessages(Map<String, String>)
public static void main(String[] args) { Map<String, String> messages = Map.of("key.apple", "manzana"); DeleteCommand command = new DeleteCommandParser().parse(List.of(args)) .orElseThrow(failure -> { StandardErrorHandler.builder() .withMessages(messages) .build().printErrorMessage(notSuccess); System.exit(1); return new RuntimeException(); }); // ... }
In the command class, use the descriptionKey attribute to associate the message key with an option or parameter:
descriptionKey
@Option(names = "--gateway-host", description = "apple", descriptionKey = "key.apple") abstract String gatewayHost();