feat: localize propertygrid class

This commit is contained in:
Myssal
2025-04-27 21:01:31 +07:00
parent 61794cf784
commit 1cb8f077f5
2 changed files with 56 additions and 1 deletions

View File

@@ -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}]";
}
}

View File

@@ -8,7 +8,7 @@ using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SpineViewer.Utils namespace SpineViewer.Utils.Localize
{ {
public static class LocalizeConfiguration public static class LocalizeConfiguration
{ {