Skip to content

Command and option descriptions are not easily localized  #1008

Open

Description

@jonsequitur

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);
        }

Activity

  1. added
    bug
    on Aug 5, 2020
  2. fredrikhr commented on Aug 5, 2020

    @fredrikhr
    Contributor

    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.

  3. fredrikhr commented on Aug 6, 2020

    @fredrikhr
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions