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 AttentionListViewComponent : ViewComponent
{
private readonly ILocalizationService _localization;
public AttentionListViewComponent(ILocalizationService localization)
{
_localization = localization;
}
public IViewComponentResult Invoke(string key)
{
var model = AttentionListCatalog.Get(key);
var model = AttentionListCatalog.Get(key, _localization);
return View(model);
}
}
@ -18,23 +26,35 @@ public class AttentionListViewModel
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, AttentionListViewModel> Lists = new()
private static readonly Dictionary<string, AttentionListData> Lists = new()
{
["current-attentions"] = new AttentionListViewModel
["current-attentions"] = new AttentionListData
{
Key = "current-attentions",
Title = "Opmærksomheder",
TitleKey = "dashboard.attentions.title",
AttentionKeys = ["attention-1", "attention-2", "attention-3"]
}
};
public static AttentionListViewModel Get(string key)
public static AttentionListViewModel Get(string key, ILocalizationService localization)
{
if (Lists.TryGetValue(key, out var list))
return list;
if (!Lists.TryGetValue(key, out var list))
throw new KeyNotFoundException($"AttentionList with key '{key}' not found");
throw new KeyNotFoundException($"AttentionList with key '{key}' not found");
return new AttentionListViewModel
{
Key = list.Key,
Title = localization.Get(list.TitleKey),
AttentionKeys = list.AttentionKeys
};
}
}

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;

View file

@ -1,12 +1,20 @@
using Microsoft.AspNetCore.Mvc;
using PlanTempus.Application.Features.Localization.Services;
namespace PlanTempus.Application.Features.Dashboard.Components;
public class BookingListViewComponent : ViewComponent
{
private readonly ILocalizationService _localization;
public BookingListViewComponent(ILocalizationService localization)
{
_localization = localization;
}
public IViewComponentResult Invoke(string key)
{
var model = BookingListCatalog.Get(key);
var model = BookingListCatalog.Get(key, _localization);
return View(model);
}
}
@ -19,24 +27,38 @@ public class BookingListViewModel
public required IReadOnlyList<string> BookingKeys { get; init; }
}
internal class BookingListData
{
public required string Key { get; init; }
public required string TitleKey { get; init; }
public required string CurrentTime { get; init; }
public required IReadOnlyList<string> BookingKeys { get; init; }
}
public static class BookingListCatalog
{
private static readonly Dictionary<string, BookingListViewModel> Lists = new()
private static readonly Dictionary<string, BookingListData> Lists = new()
{
["todays-bookings"] = new BookingListViewModel
["todays-bookings"] = new BookingListData
{
Key = "todays-bookings",
Title = "Dagens bookinger",
TitleKey = "dashboard.bookings.title",
CurrentTime = "10:45",
BookingKeys = ["booking-1", "booking-2", "booking-3", "booking-4", "booking-5", "booking-6"]
}
};
public static BookingListViewModel Get(string key)
public static BookingListViewModel Get(string key, ILocalizationService localization)
{
if (Lists.TryGetValue(key, out var list))
return list;
if (!Lists.TryGetValue(key, out var list))
throw new KeyNotFoundException($"BookingList with key '{key}' not found");
throw new KeyNotFoundException($"BookingList with key '{key}' not found");
return new BookingListViewModel
{
Key = list.Key,
Title = localization.Get(list.TitleKey),
CurrentTime = list.CurrentTime,
BookingKeys = list.BookingKeys
};
}
}

View file

@ -6,11 +6,11 @@
<i class="ph ph-calendar-check"></i>
@Model.Title
</swp-card-title>
<swp-card-action>Se alle</swp-card-action>
<swp-card-action localize="dashboard.bookings.viewAll">Se alle</swp-card-action>
</swp-card-header>
<swp-current-time>
<i class="ph ph-clock"></i>
<span>Nu: <swp-time>@Model.CurrentTime</swp-time></span>
<span><span localize="dashboard.bookings.currentTime">Nu:</span> <swp-time>@Model.CurrentTime</swp-time></span>
</swp-current-time>
<swp-card-content>
<swp-booking-list>

View file

@ -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
};
}
}

View file

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using PlanTempus.Application.Features.Localization.Services;
namespace PlanTempus.Application.Features.Dashboard.Components;
@ -7,9 +8,16 @@ namespace PlanTempus.Application.Features.Dashboard.Components;
/// </summary>
public class QuickStatViewComponent : ViewComponent
{
private readonly ILocalizationService _localization;
public QuickStatViewComponent(ILocalizationService localization)
{
_localization = localization;
}
public IViewComponentResult Invoke(string key)
{
var model = QuickStatCatalog.Get(key);
var model = QuickStatCatalog.Get(key, _localization);
return View(model);
}
}
@ -24,45 +32,57 @@ public class QuickStatViewModel
public required string Label { get; init; }
}
internal class QuickStatData
{
public required string Key { get; init; }
public required string Value { get; init; }
public required string LabelKey { get; init; }
}
/// <summary>
/// Catalog of available quick stats with their data.
/// </summary>
public static class QuickStatCatalog
{
private static readonly Dictionary<string, QuickStatViewModel> Stats = new()
private static readonly Dictionary<string, QuickStatData> Stats = new()
{
["bookings-week"] = new QuickStatViewModel
["bookings-week"] = new QuickStatData
{
Key = "bookings-week",
Value = "47",
Label = "Bookinger"
LabelKey = "dashboard.quickStats.bookings"
},
["revenue-week"] = new QuickStatViewModel
["revenue-week"] = new QuickStatData
{
Key = "revenue-week",
Value = "38.200 kr",
Label = "Omsætning"
LabelKey = "dashboard.quickStats.revenue"
},
["new-customers"] = new QuickStatViewModel
["new-customers"] = new QuickStatData
{
Key = "new-customers",
Value = "8",
Label = "Nye kunder"
LabelKey = "dashboard.quickStats.newCustomers"
},
["avg-occupancy"] = new QuickStatViewModel
["avg-occupancy"] = new QuickStatData
{
Key = "avg-occupancy",
Value = "72%",
Label = "Gns. belægning"
LabelKey = "dashboard.quickStats.avgOccupancy"
}
};
public static QuickStatViewModel Get(string key)
public static QuickStatViewModel Get(string key, ILocalizationService localization)
{
if (Stats.TryGetValue(key, out var stat))
return stat;
if (!Stats.TryGetValue(key, out var stat))
throw new KeyNotFoundException($"QuickStat with key '{key}' not found");
throw new KeyNotFoundException($"QuickStat with key '{key}' not found");
return new QuickStatViewModel
{
Key = stat.Key,
Value = stat.Value,
Label = localization.Get(stat.LabelKey)
};
}
public static IEnumerable<string> AllKeys => Stats.Keys;

View file

@ -1,12 +1,20 @@
using Microsoft.AspNetCore.Mvc;
using PlanTempus.Application.Features.Localization.Services;
namespace PlanTempus.Application.Features.Dashboard.Components;
public class QuickStatListViewComponent : ViewComponent
{
private readonly ILocalizationService _localization;
public QuickStatListViewComponent(ILocalizationService localization)
{
_localization = localization;
}
public IViewComponentResult Invoke(string key)
{
var model = QuickStatListCatalog.Get(key);
var model = QuickStatListCatalog.Get(key, _localization);
return View(model);
}
}
@ -19,24 +27,38 @@ public class QuickStatListViewModel
public required IReadOnlyList<string> StatKeys { get; init; }
}
internal class QuickStatListData
{
public required string Key { get; init; }
public required string TitleKey { get; init; }
public required string Icon { get; init; }
public required IReadOnlyList<string> StatKeys { get; init; }
}
public static class QuickStatListCatalog
{
private static readonly Dictionary<string, QuickStatListViewModel> Lists = new()
private static readonly Dictionary<string, QuickStatListData> Lists = new()
{
["this-week"] = new QuickStatListViewModel
["this-week"] = new QuickStatListData
{
Key = "this-week",
Title = "Denne uge",
TitleKey = "dashboard.quickStats.title",
Icon = "chart-line-up",
StatKeys = ["bookings-week", "revenue-week", "new-customers", "avg-occupancy"]
}
};
public static QuickStatListViewModel Get(string key)
public static QuickStatListViewModel Get(string key, ILocalizationService localization)
{
if (Lists.TryGetValue(key, out var list))
return list;
if (!Lists.TryGetValue(key, out var list))
throw new KeyNotFoundException($"QuickStatList with key '{key}' not found");
throw new KeyNotFoundException($"QuickStatList with key '{key}' not found");
return new QuickStatListViewModel
{
Key = list.Key,
Title = localization.Get(list.TitleKey),
Icon = list.Icon,
StatKeys = list.StatKeys
};
}
}

View file

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using PlanTempus.Application.Features.Localization.Services;
namespace PlanTempus.Application.Features.Dashboard.Components;
@ -7,9 +8,16 @@ namespace PlanTempus.Application.Features.Dashboard.Components;
/// </summary>
public class StatCardViewComponent : ViewComponent
{
private readonly ILocalizationService _localization;
public StatCardViewComponent(ILocalizationService localization)
{
_localization = localization;
}
public IViewComponentResult Invoke(string key)
{
var model = StatCardCatalog.Get(key);
var model = StatCardCatalog.Get(key, _localization);
return View(model);
}
}
@ -29,61 +37,84 @@ public class StatCardViewModel
public bool HasTrend => !string.IsNullOrEmpty(TrendText);
}
/// <summary>
/// Internal data for stat cards (uses localization keys).
/// </summary>
internal class StatCardData
{
public required string Key { get; init; }
public required string Value { get; init; }
public required string LabelKey { get; init; }
public string? TrendTextKey { get; init; }
public string? TrendIcon { get; init; }
public string? TrendDirection { get; init; }
public string? Variant { get; init; }
}
/// <summary>
/// Catalog of available stat cards with their data.
/// </summary>
public static class StatCardCatalog
{
private static readonly Dictionary<string, StatCardViewModel> Cards = new()
private static readonly Dictionary<string, StatCardData> Cards = new()
{
["bookings-today"] = new StatCardViewModel
["bookings-today"] = new StatCardData
{
Key = "bookings-today",
Value = "12",
Label = "Bookinger i dag",
TrendText = "4 gennemført, 2 i gang",
LabelKey = "dashboard.stats.bookingsToday",
TrendTextKey = "dashboard.stats.bookingsTrend",
TrendIcon = "ph-check-circle",
TrendDirection = "up",
Variant = "highlight"
},
["expected-revenue"] = new StatCardViewModel
["expected-revenue"] = new StatCardData
{
Key = "expected-revenue",
Value = "8.450 kr",
Label = "Forventet omsætning",
TrendText = "+12% vs. gennemsnit",
LabelKey = "dashboard.stats.expectedRevenue",
TrendTextKey = "dashboard.stats.revenueTrend",
TrendIcon = "ph-trend-up",
TrendDirection = "up",
Variant = "success"
},
["occupancy-rate"] = new StatCardViewModel
["occupancy-rate"] = new StatCardData
{
Key = "occupancy-rate",
Value = "78%",
Label = "Belægningsgrad",
TrendText = "God kapacitet",
LabelKey = "dashboard.stats.occupancyRate",
TrendTextKey = "dashboard.stats.occupancyTrend",
TrendIcon = "ph-trend-up",
TrendDirection = "up",
Variant = null
},
["needs-attention"] = new StatCardViewModel
["needs-attention"] = new StatCardData
{
Key = "needs-attention",
Value = "4",
Label = "Kræver opmærksomhed",
TrendText = null,
LabelKey = "dashboard.stats.needsAttention",
TrendTextKey = null,
TrendIcon = null,
TrendDirection = null,
Variant = "warning"
}
};
public static StatCardViewModel Get(string key)
public static StatCardViewModel Get(string key, ILocalizationService localization)
{
if (Cards.TryGetValue(key, out var card))
return card;
if (!Cards.TryGetValue(key, out var card))
throw new KeyNotFoundException($"StatCard with key '{key}' not found");
throw new KeyNotFoundException($"StatCard with key '{key}' not found");
return new StatCardViewModel
{
Key = card.Key,
Value = card.Value,
Label = localization.Get(card.LabelKey),
TrendText = card.TrendTextKey != null ? localization.Get(card.TrendTextKey) : null,
TrendIcon = card.TrendIcon,
TrendDirection = card.TrendDirection,
Variant = card.Variant
};
}
public static IEnumerable<string> AllKeys => Cards.Keys;

View file

@ -22,7 +22,7 @@
<swp-ai-insight>
<swp-ai-header>
<i class="ph ph-sparkle"></i>
<span>AI Analyse</span>
<span localize="dashboard.ai.header">AI Analyse</span>
</swp-ai-header>
<swp-ai-text>
<strong>Godt i gang!</strong> 4 af 12 bookinger er gennemført. 2 er i gang nu, og 6 venter.
@ -51,17 +51,17 @@
<!-- Quick Actions -->
<swp-card>
<swp-card-header>
<swp-card-title>Hurtige handlinger</swp-card-title>
<swp-card-title localize="dashboard.quickActions.title">Hurtige handlinger</swp-card-title>
</swp-card-header>
<swp-card-content>
<swp-quick-actions>
<swp-quick-action-btn>
<i class="ph ph-plus"></i>
Ny booking
<span localize="dashboard.quickActions.newBooking">Ny booking</span>
</swp-quick-action-btn>
<swp-quick-action-btn>
<i class="ph ph-user-plus"></i>
Ny kunde
<span localize="dashboard.quickActions.newCustomer">Ny kunde</span>
</swp-quick-action-btn>
</swp-quick-actions>
</swp-card-content>