feat StayExport - Added LocalizerService

- Added new "LocalizerService" to get localization for enum values (and other dynamic/db values in the future).
This commit is contained in:
2026-09-02 13:15:10 +02:00
parent b318f2415c
commit cf31cbc414
6 changed files with 56 additions and 20 deletions
@@ -0,0 +1,37 @@
using Microsoft.Extensions.Localization;
using Somnia.GuestLog.Resources;
namespace Somnia.GuestLog.Services;
public class LocalizerService(
IServiceProvider serviceProvider
) : ILocalizerService
{
private IStringLocalizer<LanguageLocale> Localizer
{
get
{
field ??= serviceProvider.GetRequiredService<IStringLocalizer<LanguageLocale>>();
return field;
}
}
public string GetEnumValue<TEnum>(TEnum? enumValue) where TEnum : struct, Enum
{
if (enumValue == null)
{
return GuestConsts.EmptyField;
}
return GetEnumValue(enumValue.Value);
}
public string GetEnumValue<TEnum>(TEnum enumValue) where TEnum : struct, Enum
{
string enumName = typeof(TEnum).Name;
string? strEnumValue = Enum.GetName(enumValue);
string localeKey = $"enum.{enumName}.{strEnumValue}";
return Localizer[localeKey];
}
}