using Microsoft.Extensions.Localization; using Somnia.GuestLog.Resources; namespace Somnia.GuestLog.Services; public class LocalizerService( IServiceProvider serviceProvider ) : ILocalizerService { private IStringLocalizer Localizer { get { field ??= serviceProvider.GetRequiredService>(); return field; } } public string GetEnumValue(TEnum? enumValue) where TEnum : struct, Enum { if (enumValue == null) { return GuestConsts.EmptyField; } return GetEnumValue(enumValue.Value); } public string GetEnumValue(TEnum enumValue) where TEnum : struct, Enum { string enumName = typeof(TEnum).Name; string? strEnumValue = Enum.GetName(enumValue); string localeKey = $"enum.{enumName}.{strEnumValue}"; return Localizer[localeKey]; } }