Skip to content
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

Command and option descriptions are not easily localized #1008

Open
jonsequitur opened this issue Aug 5, 2020 · 2 comments
Open

Command and option descriptions are not easily localized #1008

jonsequitur opened this issue Aug 5, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@jonsequitur
Copy link
Contributor

The incoming mechanisms for setting the culture via environment variables and directives (#951) don't allow a straightforward way to localize descriptions, because the parser is configured before the middleware that sets the culture gets executed.

Example:

        static void Main(string[] args)
        {
            // OOPS: Environment variable isn't set yet, and neither is the current culture the one we'll be using at invocation time
            var description = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_GLOBALIZATION_CULTURE") switch
            {
                "es-ES" => "hola",
                _ => "hello"
            };

            var option1 = new Option<string>("-x", description);

            new RootCommand
            {
                option1
            }.Invoke(args);
        }
@jonsequitur jonsequitur added the bug Something isn't working label Aug 5, 2020
@fredrikhr
Copy link
Contributor

fredrikhr commented Aug 5, 2020

I wonder whether we'd approach this problem by adding a LocalizedHelpBuilder that derives from the deafult HelpBuilder and uses an ILocalizer from the Microsoft.Extensions.Localization. In such a case the Description of a Command/Option/Argument would be the invariant string/key passed to the ILocalizer and would either return the invariant or localized string in the output

If we don't want to add dependency to Microsoft.Extensions.Localization we could introduce a new System.CommandLine.Localization package (similar to the System.CommandLine.Hosting package). On the other extreme side, we could make the default Help builder use localization by default.

@fredrikhr
Copy link
Contributor

I am currently working on #1013 which is still work in progress which will introduce a new package System.CommandLine.Localization and add a new extension method UseLocalization to CommandLineBuilder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants