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
This commit is contained in:
parent
1f400dcc6e
commit
ef174af0e1
36 changed files with 821 additions and 263 deletions
|
|
@ -1,12 +1,20 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using PlanTempus.Application.Features.Localization.Services;
|
||||
|
||||
namespace PlanTempus.Application.Features.Dashboard.Components;
|
||||
|
||||
public class NotificationListViewComponent : ViewComponent
|
||||
{
|
||||
private readonly ILocalizationService _localization;
|
||||
|
||||
public NotificationListViewComponent(ILocalizationService localization)
|
||||
{
|
||||
_localization = localization;
|
||||
}
|
||||
|
||||
public IViewComponentResult Invoke(string key)
|
||||
{
|
||||
var model = NotificationListCatalog.Get(key);
|
||||
var model = NotificationListCatalog.Get(key, _localization);
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
|
|
@ -19,24 +27,38 @@ public class NotificationListViewModel
|
|||
public required IReadOnlyList<string> NotificationKeys { get; init; }
|
||||
}
|
||||
|
||||
internal class NotificationListData
|
||||
{
|
||||
public required string Key { get; init; }
|
||||
public required string TitleKey { get; init; }
|
||||
public required string ActionTextKey { get; init; }
|
||||
public required IReadOnlyList<string> NotificationKeys { get; init; }
|
||||
}
|
||||
|
||||
public static class NotificationListCatalog
|
||||
{
|
||||
private static readonly Dictionary<string, NotificationListViewModel> Lists = new()
|
||||
private static readonly Dictionary<string, NotificationListData> Lists = new()
|
||||
{
|
||||
["recent-notifications"] = new NotificationListViewModel
|
||||
["recent-notifications"] = new NotificationListData
|
||||
{
|
||||
Key = "recent-notifications",
|
||||
Title = "Notifikationer",
|
||||
ActionText = "Marker alle som læst",
|
||||
TitleKey = "dashboard.notifications.title",
|
||||
ActionTextKey = "dashboard.notifications.markAllRead",
|
||||
NotificationKeys = ["notif-1", "notif-2", "notif-3", "notif-4"]
|
||||
}
|
||||
};
|
||||
|
||||
public static NotificationListViewModel Get(string key)
|
||||
public static NotificationListViewModel Get(string key, ILocalizationService localization)
|
||||
{
|
||||
if (Lists.TryGetValue(key, out var list))
|
||||
return list;
|
||||
if (!Lists.TryGetValue(key, out var list))
|
||||
throw new KeyNotFoundException($"NotificationList with key '{key}' not found");
|
||||
|
||||
throw new KeyNotFoundException($"NotificationList with key '{key}' not found");
|
||||
return new NotificationListViewModel
|
||||
{
|
||||
Key = list.Key,
|
||||
Title = localization.Get(list.TitleKey),
|
||||
ActionText = localization.Get(list.ActionTextKey),
|
||||
NotificationKeys = list.NotificationKeys
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue