forked from spectreconsole/spectre.console
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support command description localization
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"
- Loading branch information
Showing
13 changed files
with
62 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,2 @@ | ||
<Project> | ||
<Target Name="Versioning" BeforeTargets="MinVer"> | ||
<PropertyGroup Label="Build"> | ||
<MinVerDefaultPreReleaseIdentifiers>preview.0</MinVerDefaultPreReleaseIdentifiers> | ||
<MinVerVerbosity>normal</MinVerVerbosity> | ||
</PropertyGroup> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Spectre.Console.Cli/Annotations/LocalizationAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace Spectre.Console.Cli; | ||
|
||
/// <summary> | ||
/// Indicates that a "Description" feature should display its localization description. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Class)] | ||
public class LocalizationAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// Gets or Sets a strongly-typed resource class, for looking up localized strings, etc. | ||
/// </summary> | ||
public Type ResourceClass { get; set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LocalizationAttribute"/> class. | ||
/// </summary> | ||
/// <param name="resourceClass"> | ||
/// The type of the resource manager. | ||
/// </param> | ||
public LocalizationAttribute(Type resourceClass) | ||
{ | ||
ResourceClass = resourceClass; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Spectre.Console.Cli/Internal/Extensions/LocalizationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters