You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Command and option descriptions are not easily localized #1008
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:
staticvoidMain(string[]args){// OOPS: Environment variable isn't set yet, and neither is the current culture the one we'll be using at invocation timevardescription=Environment.GetEnvironmentVariable("DOTNET_SYSTEM_GLOBALIZATION_CULTURE")switch{"es-ES"=>"hola",
_ =>"hello"};varoption1=newOption<string>("-x",description);newRootCommand{option1}.Invoke(args);}
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.
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.
Activity
fredrikhr commentedon Aug 5, 2020
I wonder whether we'd approach this problem by adding a
LocalizedHelpBuilderthat derives from the deafult HelpBuilder and uses anILocalizerfrom theMicrosoft.Extensions.Localization. In such a case theDescriptionof aCommand/Option/Argumentwould be the invariant string/key passed to theILocalizerand would either return the invariant or localized string in the outputIf we don't want to add dependency to
Microsoft.Extensions.Localizationwe could introduce a newSystem.CommandLine.Localizationpackage (similar to theSystem.CommandLine.Hostingpackage). On the other extreme side, we could make the default Help builder use localization by default.fredrikhr commentedon Aug 6, 2020
I am currently working on #1013 which is still work in progress which will introduce a new package
System.CommandLine.Localizationand add a new extension methodUseLocalizationtoCommandLineBuilder.