Skip to content

Is there any possibility to localize error messages? #1946

@lukaseckert

Description

@lukaseckert

Hi,
first, thanks for this great piece of software! Currently I'm trying to localize the most common messages which a user might see when using a picocli-based app. Via the resource bundle, it was easy to translate options, usage help, etc. 👍 However this doesn't work for error/help messages, resulting in a mix of English and German in the output:

Unknown option: '--help'
Aufruf: my-cli-ap ...
Hier kommt eine Beschreibung auf Deutsch.
Optionen:
-n, --node=

I see that "Unknown option:" is hard-coded in CommandLine.UnmatchedArgumentException.describe() (line 18669), and requires some special handling for the plural, which cannot be solved by simple resource files. Then I checked if it would be possible so subclass the Interpreter to override describe(). This is obviously not a good idea as describe() does more than only building the string, and is also impossible as there is not setter for an extended Interpreter implementation.

I wondered if there are any plans to offer an extension point where a custom "MessageProvider" may be set. This interface could then have methods like buildUnknownOptionMessage(String optionName, boolean isPlural) and be implemented for most languages.
The same applies for many more methods, e.g. readUserInput() ("Enter value for %s: ")

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions