PlanTempusApp/PlanTempus.Application/Features/Dashboard/Components/AttentionList/AttentionListViewComponent.cs
Janus C. H. Knudsen ef174af0e1 Adds localization support across application views
Implements localization for dashboard, cash register, account, and profile sections

Adds localization keys for various UI elements, improving internationalization support
Refactors view components to use ILocalizationService for dynamic text rendering
Prepares ground for multi-language support with translation-ready markup
2026-01-12 15:42:18 +01:00

60 lines
1.7 KiB
C#

using Microsoft.AspNetCore.Mvc;
using PlanTempus.Application.Features.Localization.Services;
namespace PlanTempus.Application.Features.Dashboard.Components;
public class AttentionListViewComponent : ViewComponent
{
private readonly ILocalizationService _localization;
public AttentionListViewComponent(ILocalizationService localization)
{
_localization = localization;
}
public IViewComponentResult Invoke(string key)
{
var model = AttentionListCatalog.Get(key, _localization);
return View(model);
}
}
public class AttentionListViewModel
{
public required string Key { get; init; }
public required string Title { get; init; }
public required IReadOnlyList<string> AttentionKeys { get; init; }
}
internal class AttentionListData
{
public required string Key { get; init; }
public required string TitleKey { get; init; }
public required IReadOnlyList<string> AttentionKeys { get; init; }
}
public static class AttentionListCatalog
{
private static readonly Dictionary<string, AttentionListData> Lists = new()
{
["current-attentions"] = new AttentionListData
{
Key = "current-attentions",
TitleKey = "dashboard.attentions.title",
AttentionKeys = ["attention-1", "attention-2", "attention-3"]
}
};
public static AttentionListViewModel Get(string key, ILocalizationService localization)
{
if (!Lists.TryGetValue(key, out var list))
throw new KeyNotFoundException($"AttentionList with key '{key}' not found");
return new AttentionListViewModel
{
Key = list.Key,
Title = localization.Get(list.TitleKey),
AttentionKeys = list.AttentionKeys
};
}
}