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:
Janus C. H. Knudsen 2026-01-12 15:42:18 +01:00
parent 1f400dcc6e
commit ef174af0e1
36 changed files with 821 additions and 263 deletions

View file

@ -1,12 +1,20 @@
using Microsoft.AspNetCore.Mvc;
using PlanTempus.Application.Features.Localization.Services;
namespace PlanTempus.Application.Features.Dashboard.Components;
public class BookingItemViewComponent : ViewComponent
{
private readonly ILocalizationService _localization;
public BookingItemViewComponent(ILocalizationService localization)
{
_localization = localization;
}
public IViewComponentResult Invoke(string key)
{
var model = BookingItemCatalog.Get(key);
var model = BookingItemCatalog.Get(key, _localization);
return View(model);
}
}
@ -21,23 +29,36 @@ public class BookingItemViewModel
public required string EmployeeInitials { get; init; }
public required string EmployeeName { get; init; }
public required string Status { get; init; }
public required string StatusText { get; init; }
public string? IndicatorColor { get; init; }
}
public string StatusText => Status switch
{
"completed" => "Gennemført",
"inprogress" => "I gang",
"confirmed" => "Bekræftet",
"pending" => "Afventer",
_ => Status
};
internal class BookingItemData
{
public required string Key { get; init; }
public required string TimeStart { get; init; }
public required string TimeEnd { get; init; }
public required string Service { get; init; }
public required string CustomerName { get; init; }
public required string EmployeeInitials { get; init; }
public required string EmployeeName { get; init; }
public required string Status { get; init; }
public string? IndicatorColor { get; init; }
}
public static class BookingItemCatalog
{
private static readonly Dictionary<string, BookingItemViewModel> Bookings = new()
private static readonly Dictionary<string, string> StatusKeys = new()
{
["booking-1"] = new BookingItemViewModel
["completed"] = "dashboard.bookings.status.completed",
["inprogress"] = "dashboard.bookings.status.inProgress",
["confirmed"] = "dashboard.bookings.status.confirmed",
["pending"] = "dashboard.bookings.status.pending"
};
private static readonly Dictionary<string, BookingItemData> Bookings = new()
{
["booking-1"] = new BookingItemData
{
Key = "booking-1",
TimeStart = "08:00",
@ -48,7 +69,7 @@ public static class BookingItemCatalog
EmployeeName = "Maria Hansen",
Status = "completed"
},
["booking-2"] = new BookingItemViewModel
["booking-2"] = new BookingItemData
{
Key = "booking-2",
TimeStart = "08:30",
@ -59,7 +80,7 @@ public static class BookingItemCatalog
EmployeeName = "Anna Sørensen",
Status = "completed"
},
["booking-3"] = new BookingItemViewModel
["booking-3"] = new BookingItemData
{
Key = "booking-3",
TimeStart = "09:00",
@ -70,7 +91,7 @@ public static class BookingItemCatalog
EmployeeName = "Peter Kristensen",
Status = "completed"
},
["booking-4"] = new BookingItemViewModel
["booking-4"] = new BookingItemData
{
Key = "booking-4",
TimeStart = "10:30",
@ -82,7 +103,7 @@ public static class BookingItemCatalog
Status = "inprogress",
IndicatorColor = "blue"
},
["booking-5"] = new BookingItemViewModel
["booking-5"] = new BookingItemData
{
Key = "booking-5",
TimeStart = "10:00",
@ -94,7 +115,7 @@ public static class BookingItemCatalog
Status = "inprogress",
IndicatorColor = "purple"
},
["booking-6"] = new BookingItemViewModel
["booking-6"] = new BookingItemData
{
Key = "booking-6",
TimeStart = "11:00",
@ -108,12 +129,28 @@ public static class BookingItemCatalog
}
};
public static BookingItemViewModel Get(string key)
public static BookingItemViewModel Get(string key, ILocalizationService localization)
{
if (Bookings.TryGetValue(key, out var booking))
return booking;
if (!Bookings.TryGetValue(key, out var booking))
throw new KeyNotFoundException($"BookingItem with key '{key}' not found");
throw new KeyNotFoundException($"BookingItem with key '{key}' not found");
var statusText = StatusKeys.TryGetValue(booking.Status, out var statusKey)
? localization.Get(statusKey)
: booking.Status;
return new BookingItemViewModel
{
Key = booking.Key,
TimeStart = booking.TimeStart,
TimeEnd = booking.TimeEnd,
Service = booking.Service,
CustomerName = booking.CustomerName,
EmployeeInitials = booking.EmployeeInitials,
EmployeeName = booking.EmployeeName,
Status = booking.Status,
StatusText = statusText,
IndicatorColor = booking.IndicatorColor
};
}
public static IEnumerable<string> AllKeys => Bookings.Keys;