Skip to content

ResourceBundle

H90 edited this page May 15, 2021 · 11 revisions

Call the withMessages(Map<String, String>) method on the generated parser, with a map created from the bundle:

public static void main(String[] args) {
  ResourceBundle bundle = ResourceBundle.getBundle("myResource");
  DeleteCommand c = new DeleteCommand_Parser()
    .withMessageMap(toMap(bundle))
    .parseOrExit(args);
  // ...
}

private static Map<String, String> toMap(ResourceBundle bundle) {
  return Collections.list(bundle.getKeys()).stream()
    .collect(Collectors.toMap(Function.identity(), bundle::getString));
}

Clone this wiki locally