diff --git a/SpineViewer/Utils/Localize/LocalizeAttribute.cs b/SpineViewer/Utils/Localize/LocalizeAttribute.cs new file mode 100644 index 0000000..bbc1314 --- /dev/null +++ b/SpineViewer/Utils/Localize/LocalizeAttribute.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Resources; +using System.Text; +using System.Threading.Tasks; + +namespace SpineViewer.Utils.Localize +{ + public class LocalizedDisplayNameAttribute : DisplayNameAttribute + { + private readonly ResourceManager _resourceManager; + private readonly string _resourceKey; + + public LocalizedDisplayNameAttribute(Type resourceSource, string resourceKey) + { + _resourceManager = new ResourceManager(resourceSource); + _resourceKey = resourceKey; + } + + public override string DisplayName => _resourceManager.GetString(_resourceKey) ?? $"[{_resourceKey}]"; + } + + public class LocalizedCategoryAttribute : CategoryAttribute + { + private readonly ResourceManager _resourceManager; + private readonly string _resourceKey; + + public LocalizedCategoryAttribute(Type resourceSource, string resourceKey) + { + _resourceManager = new ResourceManager(resourceSource); + _resourceKey = resourceKey; + } + + protected override string GetLocalizedString(string value) + { + return _resourceManager.GetString(_resourceKey) ?? $"[{_resourceKey}]"; + } + } + + public class LocalizedDescriptionAttribute : DescriptionAttribute + { + private readonly ResourceManager _resourceManager; + private readonly string _resourceKey; + + public LocalizedDescriptionAttribute(Type resourceSource, string resourceKey) + { + _resourceManager = new ResourceManager(resourceSource); + _resourceKey = _resourceKey; + } + + public override string Description => _resourceManager.GetString(_resourceKey) ?? $"[{_resourceKey}]"; + } +} diff --git a/SpineViewer/Utils/LocalizeConfiguration.cs b/SpineViewer/Utils/Localize/LocalizeConfiguration.cs similarity index 97% rename from SpineViewer/Utils/LocalizeConfiguration.cs rename to SpineViewer/Utils/Localize/LocalizeConfiguration.cs index 95a5f9f..ed636d6 100644 --- a/SpineViewer/Utils/LocalizeConfiguration.cs +++ b/SpineViewer/Utils/Localize/LocalizeConfiguration.cs @@ -8,7 +8,7 @@ using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; -namespace SpineViewer.Utils +namespace SpineViewer.Utils.Localize { public static class LocalizeConfiguration {