2021-04-12 01:09:54 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
namespace PKHeX.Core;
|
2021-04-12 01:09:54 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.Delegate | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter)]
|
|
|
|
|
public sealed class LocalizedDescriptionAttribute : DescriptionAttribute
|
|
|
|
|
{
|
|
|
|
|
public static IReadOnlyDictionary<string, string> Localizer { private get; set; } = new Dictionary<string, string>();
|
2021-04-12 01:09:54 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
public readonly string Fallback;
|
|
|
|
|
public readonly string Key;
|
2021-04-12 01:09:54 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
public LocalizedDescriptionAttribute(string fallback, [CallerMemberName] string? key = null)
|
|
|
|
|
{
|
|
|
|
|
Key = $"LocalizedDescription.{key!}";
|
|
|
|
|
Fallback = fallback;
|
2021-04-12 01:09:54 +00:00
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
|
|
public override string Description => Localizer.TryGetValue(Key, out var result) ? result : Fallback;
|
2021-04-12 01:09:54 +00:00
|
|
|
|
}
|