GuestLog - Localization - Initial Implementation

This commit is contained in:
2026-06-24 12:54:20 +02:00
parent d93ba3d9ee
commit e7e9fb1d12
17 changed files with 786 additions and 78 deletions
+19 -1
View File
@@ -1,4 +1,7 @@
<!DOCTYPE html>
@using System.Globalization
@using Microsoft.AspNetCore.Localization
<!DOCTYPE html>
<html lang="en">
<head>
@@ -23,3 +26,18 @@
</body>
</html>
@code {
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
protected override void OnInitialized()
{
HttpContext?.Response.Cookies.Append(
CookieRequestCultureProvider.DefaultCookieName,
CookieRequestCultureProvider.MakeCookieValue(
new RequestCulture(
CultureInfo.CurrentCulture,
CultureInfo.CurrentUICulture)));
}
}
@@ -10,7 +10,7 @@
<DialogActions>
<MudButton Color="Color.Primary" Variant="Variant.Filled" EndIcon="@Icons.Material.Filled.Close"
OnClick="Submit">
Close
@LanguageLocale.general_btnClose
</MudButton>
</DialogActions>
</MudDialog>
@@ -1,60 +1,64 @@
@using System.Linq;
@using FluentValidation;
@using Somnia.GuestLog.Models.DTOs;
@using Somnia.GuestLog.Services;
@using Somnia.GuestLog.Validators;
<MudForm @ref="@_form" Model="@Model" Validation="@(guestDocValidator.ValidateValue)" ValidationDelay="0"
@inject IDataListService dataListService;
@inject IValidator<GuestDocumentDTO> guestDocValidator;
@inject IStringLocalizer<LanguageLocale> lang;
<MudForm @ref="@_form" Model="@Model" Validation="@((guestDocValidator as GuestDocumentDTOValidator)!.ValidateValue)" ValidationDelay="0"
ReadOnly="@ReadOnly">
<MudGrid>
<MudItem xs="12" md="6">
<MudPaper Class="pa-4" Elevation="3" Height="100%">
<MudText Typo="Typo.subtitle1" Align="Align.Center">Document Details</MudText>
<MudText Typo="Typo.subtitle1" Align="Align.Center">@LanguageLocale.control_GuestDocForm_sectionDocument</MudText>
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
<MudStack Row>
<MudSelect @bind-Value="Model.DocumentType" For="@(() => Model.DocumentType)" Label="DocumentType"
<MudSelect @bind-Value="Model.DocumentType" For="@(() => Model.DocumentType)" Label="@LanguageLocale.dto_GuestDocument_DocumentType"
Required>
@foreach (string docType in GuestConsts.DocumentTypeList)
@foreach (string docType in dataListService.GetDataListByName(GuestConsts.DataList_DocumentTypes))
{
<MudSelectItem Value="docType">@docType</MudSelectItem>
<MudSelectItem Value="docType">@lang[$"dataList.DocumentType.{docType}"]</MudSelectItem>
}
</MudSelect>
<MudTextField @bind-Value="Model.DocumentNum" For="@(() => Model.DocumentNum)" Label="Document Num"
<MudTextField @bind-Value="Model.DocumentNum" For="@(() => Model.DocumentNum)" Label="@LanguageLocale.dto_GuestDocument_DocumentNum"
Immediate="true" Required />
</MudStack>
<MudStack Row>
<MudDatePicker @bind-Date="Model.IssueDate" For="@(() => Model.IssueDate)" Label="Issue Date"
<MudDatePicker @bind-Date="Model.IssueDate" For="@(() => Model.IssueDate)" Label="@LanguageLocale.dto_GuestDocument_IssueDate"
Clearable OpenTo="OpenTo.Year" Editable />
<MudTextField @bind-Value="Model.SupportNum" For="@(() => Model.SupportNum)" Label="Support Num"
<MudTextField @bind-Value="Model.SupportNum" For="@(() => Model.SupportNum)" Label="@LanguageLocale.dto_GuestDocument_SupportNum"
Immediate="true" Required="@isSuportNumberRequired" />
</MudStack>
<MudSelect @bind-Value="Model.Nationality" For="@(() => Model.Nationality)" Label="Nationality">
@foreach (var countryPair in GuestConsts.CountryList)
{
<MudSelectItem Value="countryPair.Key">@countryPair.Value</MudSelectItem>
}
</MudSelect>
<MudAutocomplete T="string" @bind-Value="Model.Nationality" For="@(() => Model.Nationality)" Label="@LanguageLocale.dto_GuestDocument_Nationality"
SearchFunc="@SearchCountryCodes" ToStringFunc="@(e=> string.IsNullOrEmpty(e) ? "" : lang[$"dataList.CountryCode.{e}"])"
SelectValueOnTab="true" AdornmentIcon="@Icons.Material.Filled.Search" />
</MudPaper>
</MudItem>
<MudItem xs="12" md="6">
<MudPaper Class="pa-4" Elevation="3" Height="100%">
<MudText Typo="Typo.subtitle1" Align="Align.Center">Customer Details</MudText>
<MudText Typo="Typo.subtitle1" Align="Align.Center">@LanguageLocale.control_GuestDocForm_sectionGuest</MudText>
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
<MudTextField @bind-Value="Model.Name" For="@(() => Model.Name)" Immediate="true" Label="Name" />
<MudTextField @bind-Value="Model.Name" For="@(() => Model.Name)" Immediate="true" Label="@LanguageLocale.dto_GuestDocument_Name" />
<MudTextField @bind-Value="Model.Surname" For="@(() => Model.Surname)" Immediate="true"
Label="Surname" />
Label="@LanguageLocale.dto_GuestDocument_Surname" />
<MudTextField @bind-Value="Model.Surname2" For="@(() => Model.Surname2)" Immediate="true"
Label="Surname2" />
<MudStack Row>
<MudDatePicker @bind-Date="Model.BirthDate" For="@(() => Model.BirthDate)" Label="BirthDate"
<MudDatePicker @bind-Date="Model.BirthDate" For="@(() => Model.BirthDate)" Label="@LanguageLocale.dto_GuestDocument_BirthDate"
Clearable OpenTo="OpenTo.Year" Editable />
<MudSelect @bind-Value="Model.Gender" For="@(() => Model.Gender)" Label="Gender">
@foreach (var genderPair in GuestConsts.GenderList)
<MudSelect @bind-Value="Model.Gender" For="@(() => Model.Gender)" Label="@LanguageLocale.dto_GuestDocument_Gender">
@foreach (string gender in dataListService.GetDataListByName(GuestConsts.DataList_GenderOptions))
{
<MudSelectItem Value="genderPair.Key">@genderPair.Value</MudSelectItem>
<MudSelectItem Value="gender">@lang[$"dataList.GenderOption.{gender}"]</MudSelectItem>
}
</MudSelect>
</MudStack>
@@ -63,41 +67,39 @@
<MudItem xs="12" md="6">
<MudPaper Class="pa-4" Elevation="3" Height="100%">
<MudText Typo="Typo.subtitle1" Align="Align.Center">Contact Details</MudText>
<MudText Typo="Typo.subtitle1" Align="Align.Center">@LanguageLocale.control_GuestDocForm_sectionContact</MudText>
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
<MudStack Row>
<MudTextField @bind-Value="Model.PhoneNumber" For="@(() => Model.PhoneNumber)" Immediate="true"
Label="Phone Number" />
Label="@LanguageLocale.dto_GuestDocument_PhoneNumber" />
<MudTextField @bind-Value="Model.EmailAddress" For="@(() => Model.EmailAddress)" Immediate="true"
Label="Email" />
Label="@LanguageLocale.dto_GuestDocument_EmailAddress" />
</MudStack>
</MudPaper>
</MudItem>
<MudItem xs="12" md="6">
<MudPaper Class="pa-4" Elevation="3" Height="100%">
<MudText Typo="Typo.subtitle1" Align="Align.Center">Address</MudText>
<MudText Typo="Typo.subtitle1" Align="Align.Center">@LanguageLocale.control_GuestDocForm_sectionAddress</MudText>
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
<MudTextField @bind-Value="Model.Address" For="@(() => Model.Address)" Immediate="true" Label="Address" />
<MudTextField @bind-Value="Model.Address" For="@(() => Model.Address)" Immediate="true" Label="@LanguageLocale.dto_GuestDocument_Address" />
<MudStack Row>
<MudTextField @bind-Value="Model.AddressCity" For="@(() => Model.AddressCity)" Immediate="true"
Label="City" />
Label="@LanguageLocale.dto_GuestDocument_AddressCity" />
<MudTextField @bind-Value="Model.AddressProvince" For="@(() => Model.AddressProvince)" Immediate="true"
Label="Province" />
Label="@LanguageLocale.dto_GuestDocument_AddressProvince" />
<MudTextField @bind-Value="Model.AddressState" For="@(() => Model.AddressState)" Immediate="true"
Label="State" />
Label="@LanguageLocale.dto_GuestDocument_AddressState" />
</MudStack>
<MudStack Row>
<MudSelect @bind-Value="Model.AddressCountry" For="@(() => Model.AddressCountry)" Label="Country">
@foreach (var countryPair in GuestConsts.CountryList)
{
<MudSelectItem Value="countryPair.Key">@countryPair.Value</MudSelectItem>
}
</MudSelect>
<MudAutocomplete T="string" @bind-Value="Model.AddressCountry" For="@(() => Model.AddressCountry)" Label="@LanguageLocale.dto_GuestDocument_AddressCountry"
SearchFunc="@SearchCountryCodes" ToStringFunc="@(e=> string.IsNullOrEmpty(e) ? "" : lang[$"dataList.CountryCode.{e}"])"
SelectValueOnTab="true" AdornmentIcon="@Icons.Material.Filled.Search" />
<MudTextField @bind-Value="Model.ZipCode" For="@(() => Model.ZipCode)" Immediate="true"
Label="ZipCode" />
Label="@LanguageLocale.dto_GuestDocument_ZipCode" />
</MudStack>
</MudPaper>
</MudItem>
@@ -115,7 +117,7 @@
private MudForm _form = null!;
private readonly GuestDocumentDTOValidator guestDocValidator = new();
private Dictionary<string, string>? countryDict = null;
private bool isSuportNumberRequired { get => Model?.Nationality == "ESP"; }
private string CreateTimeString
@@ -141,4 +143,27 @@
return _form.IsValid;
}
private async Task<IEnumerable<string>> SearchCountryCodes(string value, CancellationToken token)
{
// if text is null or empty, show complete list
if (string.IsNullOrEmpty(value)) {
return new string[0];
}
if(countryDict is null || countryDict.Count == 0) {
var countryCodeSet = dataListService.GetDataListByName(GuestConsts.DataList_CountryCodes);
countryDict = new(countryCodeSet.Count);
//Init dict.
foreach(string code in dataListService.GetDataListByName(GuestConsts.DataList_CountryCodes))
{
countryDict.Add(code, lang[$"dataList.CountryCode.{code}"]);
}
}
return countryDict
.Where(x => x.Value.Contains(value, StringComparison.InvariantCultureIgnoreCase))
.Select(x => x.Key);
}
}
@@ -1,6 +1,6 @@
<MudDialog>
<TitleContent>
<MudText Typo="Typo.subtitle1" Align="Align.Center">In progress...</MudText>
<MudText Typo="Typo.subtitle1" Align="Align.Center">@LanguageLocale.general_inProgressMsg</MudText>
</TitleContent>
<DialogContent>
<div class="d-flex flex-grow-1 flex-wrap justify-center align-center ma-8">
@@ -7,6 +7,7 @@
@inject NavigationManager Navigation
@inject ISnackbar Snackbar
@inject IDialogService DialogService
@inject IStringLocalizer<LanguageLocale> Lang
<PageTitle>Somnia - Guest Docs</PageTitle>
@@ -16,7 +17,7 @@
<MudSpacer />
<MudButton Variant="Variant.Filled" Color="Color.Success" Size="Size.Small" StartIcon="@Icons.Material.Filled.Add"
OnClick="() => BtnNewGuest()">
New Guest
@LanguageLocale.page_GuestDocList_btnNewGuest
</MudButton>
</MudStack>
@@ -36,21 +37,23 @@
<MudStack Class="ml-auto" Row="true" AlignItems="AlignItems.End">
<MudButton StartIcon="@Icons.Material.Outlined.Refresh" Variant="Variant.Outlined" Size="Size.Small"
OnClick="() => LoadDataAsync()">
Reload Data
@LanguageLocale.general_reloadData
</MudButton>
<MudButton StartIcon="@Icons.Material.Outlined.ViewColumn" Variant="Variant.Outlined" Size="Size.Small"
OnClick="(args) => BtnConfigureColumnsClick(args)">
Configure Columns
@LanguageLocale.general_ConfigureColumns
</MudButton>
</MudStack>
</ToolBarContent>
<Columns>
<PropertyColumn Property="x => x.DocumentType" Hideable="false" />
<PropertyColumn Property="x => x.DocumentNum" Hideable="false" />
<PropertyColumn Property="x => x.Name" />
<PropertyColumn Property="x => x.Surname" />
<PropertyColumn Property="x => x.Nationality" />
<PropertyColumn Property="x => x.UpdateTime" />
<PropertyColumn Property="x => x.DocumentType" Hideable="false"
Title="@LanguageLocale.dto_GuestDocument_DocumentType" />
<PropertyColumn Property="x => x.DocumentNum" Hideable="false"
Title="@LanguageLocale.dto_GuestDocument_DocumentNum" />
<PropertyColumn Property="x => x.Name" Title="@LanguageLocale.dto_GuestDocument_Name" />
<PropertyColumn Property="x => x.Surname" Title="@LanguageLocale.dto_GuestDocument_Surname" />
<PropertyColumn Property="x => x.Nationality" Title="@LanguageLocale.dto_GuestDocument_Surname2" />
<PropertyColumn Property="x => x.UpdateTime" Title="@LanguageLocale.dto_GuestDocument_UpdateTime" />
<TemplateColumn CellClass="d-flex justify-between" Title="Options" StickyRight Hideable="false"
ShowColumnOptions="false">
@@ -66,10 +69,11 @@
<MudMessageBox @ref="_msgBoxConfirmDelete" Title="Warning" CancelText="Cancel">
<MessageContent>
Deleting can <b><i>not</i></b> be undone!
@LanguageLocale.general_confirmDeleteMsg
</MessageContent>
<YesButton>
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.DeleteForever">Delete!
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.DeleteForever">
@LanguageLocale.general_btnDelete
</MudButton>
</YesButton>
</MudMessageBox>
@@ -19,11 +19,11 @@
<MudSpacer />
<MudButton Variant="Variant.Filled" Color="Color.Success" Size="Size.Small" StartIcon="@Icons.Material.Filled.Add"
OnClick="() => BtnSaveNewGuest()">
Create
@LanguageLocale.general_btnCreate
</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Default" Size="Size.Small"
StartIcon="@Icons.Material.Filled.ArrowBack" OnClick="() => BtnReturn()">
Return
@LanguageLocale.general_btnReturn
</MudButton>
</MudStack>
<GuestDocForm @ref="_form" />
@@ -6,8 +6,10 @@
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using Microsoft.Extensions.Localization
@using MudBlazor
@using MudBlazor.Services
@using Somnia.GuestLog
@using Somnia.GuestLog.Components
@using Somnia.GuestLog.Components.Layout
@using Somnia.GuestLog.Resources