Skip to content

Localization #269

Answered by CyberSinh
Skeferstat asked this question in Q&A
Discussion options

You must be logged in to vote

Hi,

Attributes only support constant values. But you can workaround this limitation like this:

internal sealed class LocalizedDescriptionAttribute : DescriptionAttribute
{
   public string Key { get; }

   public LocalizedDescriptionAttribute(string key) :
      base(SRCli.ResourceManager.GetString(key) ?? throw new ArgumentOutOfRangeException(nameof(key)))
   {
      Key = key;
   }
}

internal sealed class ConfigureCommandSettings : CommandSettings
{
    [CommandOption("--name")]
    [LocalizedDescription(nameof(SRCli.NameOption))]
    public string? Name { get; init; }
}

Hope this helps.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by patriksvensson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants