mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-13 15:42:50 +08:00

eg. [CommandOption("-a|--args")] [Description(nameof(Str.GitArgs))] [Localization(typeof(Str))] public string Args { get; set; } The program will go to the autogenerated class "Str.designer.cs" of the Resx file, to looking for local value of the the resource symbol "GitArgs" , instead of displaying the original: "GitArgs"
21 lines
648 B
C#
21 lines
648 B
C#
namespace Spectre.Console.Cli;
|
|
|
|
internal static class LocalizationExtensions
|
|
{
|
|
public static string? LocalizedDescription(this MemberInfo me)
|
|
{
|
|
var description = me.GetCustomAttribute<DescriptionAttribute>();
|
|
if (description is null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var localization = me.GetCustomAttribute<LocalizationAttribute>();
|
|
string? localizedText;
|
|
return (localizedText = localization?.ResourceClass
|
|
.GetProperty(description.Description)?
|
|
.GetValue(default) as string) != null
|
|
? localizedText
|
|
: description.Description;
|
|
}
|
|
} |