From 5e8ebf7e2a008ad523513e7bf20ebf2e9e635edd Mon Sep 17 00:00:00 2001 From: "Johnny.Ratton" Date: Wed, 20 Dec 2023 15:23:48 +0100 Subject: [PATCH] =?UTF-8?q?Continuit=C3=A9=20de=20la=20globalisation=20ave?= =?UTF-8?q?c=20un=20bug=20sur=20la=20vue=20EmployeeData?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BlazorProject/BlazorProject.csproj | 24 +++++ BlazorProject/Layout/MainLayout.razor | 7 +- BlazorProject/Layout/NavMenu.razor | 5 + BlazorProject/Models/Employee.cs | 11 ++ BlazorProject/Pages/EmployeeData.razor | 65 ++++++++++++ BlazorProject/Pages/EmployeeData.razor.cs | 54 ++++++++++ BlazorProject/Pages/List.razor | 15 ++- BlazorProject/Program.cs | 17 +++ BlazorProject/Ressources/App.Designer.cs | 102 ++++++++++++++++++ BlazorProject/Ressources/App.fr.Designer.cs | 108 ++++++++++++++++++++ BlazorProject/Ressources/App.fr.resx | 48 +++++++++ BlazorProject/Ressources/App.resx | 48 +++++++++ BlazorProject/wwwroot/index.html | 12 +++ 13 files changed, 507 insertions(+), 9 deletions(-) create mode 100644 BlazorProject/Models/Employee.cs create mode 100644 BlazorProject/Pages/EmployeeData.razor create mode 100644 BlazorProject/Pages/EmployeeData.razor.cs create mode 100644 BlazorProject/Ressources/App.Designer.cs create mode 100644 BlazorProject/Ressources/App.fr.Designer.cs create mode 100644 BlazorProject/Ressources/App.fr.resx create mode 100644 BlazorProject/Ressources/App.resx diff --git a/BlazorProject/BlazorProject.csproj b/BlazorProject/BlazorProject.csproj index 039219d..67b1903 100644 --- a/BlazorProject/BlazorProject.csproj +++ b/BlazorProject/BlazorProject.csproj @@ -16,16 +16,40 @@ + FetchData.razor + + True + True + App.resx + + + True + True + App.fr.resx + + + + ResXFileCodeGenerator + App.Designer.cs + + + ResXFileCodeGenerator + App.fr.Designer.cs + + + + true + diff --git a/BlazorProject/Layout/MainLayout.razor b/BlazorProject/Layout/MainLayout.razor index e465845..a753838 100644 --- a/BlazorProject/Layout/MainLayout.razor +++ b/BlazorProject/Layout/MainLayout.razor @@ -1,4 +1,5 @@ -@inherits LayoutComponentBase +@using System.Globalization +@inherits LayoutComponentBase
+
diff --git a/BlazorProject/Models/Employee.cs b/BlazorProject/Models/Employee.cs new file mode 100644 index 0000000..f1ba024 --- /dev/null +++ b/BlazorProject/Models/Employee.cs @@ -0,0 +1,11 @@ +namespace BlazorProject.Models; + +public class Employee +{ + public string Name { get; set; } + public string Gender { get; set; } + public string City { get; set; } + public int Salary { get; set; } + public DateTime JoiningDate { get; set; } + +} \ No newline at end of file diff --git a/BlazorProject/Pages/EmployeeData.razor b/BlazorProject/Pages/EmployeeData.razor new file mode 100644 index 0000000..6a3dfa0 --- /dev/null +++ b/BlazorProject/Pages/EmployeeData.razor @@ -0,0 +1,65 @@ +@page "/employee" + +@using BlazorProject.Models + +

@title

+
+ +
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ +
+ +
+
+
+ + + + @foreach (string header in TableHeader) + { + + } + + + + @foreach (Employee emp in lstEmployees) + { + + + + + + + + } + +
+ @Localize[header] +
@emp.Name@Localize[emp.Gender]@emp.City@emp.Salary.ToString("C2")@emp.JoiningDate
+
+
\ No newline at end of file diff --git a/BlazorProject/Pages/EmployeeData.razor.cs b/BlazorProject/Pages/EmployeeData.razor.cs new file mode 100644 index 0000000..cf31a63 --- /dev/null +++ b/BlazorProject/Pages/EmployeeData.razor.cs @@ -0,0 +1,54 @@ +using BlazorProject.Models; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Localization; +using Microsoft.JSInterop; +using Newtonsoft.Json; + +namespace BlazorProject.Pages; + +public partial class EmployeeData +{ + [Inject] public IStringLocalizer Localize { get; set; } + [Inject] public IJSRuntime JSRuntime { get; set; } + + Employee employee = new Employee(); + + List lstEmployees = new List(); + + string title; + + string companyName = "Phrase"; + + string[] TableHeader = { "Name", "Gender", "City", "Salary", "Joining Date" }; + + protected override async Task OnInitializedAsync() + { + setTitle(); + var empGetJS = (IJSInProcessRuntime)JSRuntime; + var empList = await empGetJS.InvokeAsync("employeeData.get"); + FetchEmployeeFromLocalStorage(empList); + } + + void SaveEmployeeToLocalStorage() + { + employee.JoiningDate = DateTime.Now; + lstEmployees.Add(employee); + var empSetJS = (IJSInProcessRuntime)JSRuntime; + empSetJS.InvokeVoid("employeeData.set", JsonConvert.SerializeObject(lstEmployees)); + employee = new Employee(); + } + + void FetchEmployeeFromLocalStorage(string empList) + { + if (empList != null) + { + lstEmployees = JsonConvert.DeserializeObject>(empList); + } + } + + void setTitle() + { + string localizedTitle = Localize["EmployeeData"]; + title = string.Format(localizedTitle, companyName); + } +} \ No newline at end of file diff --git a/BlazorProject/Pages/List.razor b/BlazorProject/Pages/List.razor index 7ab3f3f..93db0e2 100644 --- a/BlazorProject/Pages/List.razor +++ b/BlazorProject/Pages/List.razor @@ -18,14 +18,13 @@ - @if (File.Exists($"{WebHostEnvironment.BaseAddress}/images/{context.Name}.png")) - { - @context.DisplayName - } - else - { - @context.DisplayName - } + @(context.Name) diff --git a/BlazorProject/Program.cs b/BlazorProject/Program.cs index 407b7ca..f2ef32a 100644 --- a/BlazorProject/Program.cs +++ b/BlazorProject/Program.cs @@ -8,6 +8,8 @@ using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using BlazorProject; using BlazorProject.Services; +using Microsoft.Extensions.Localization; +using Microsoft.JSInterop; var builder = WebAssemblyHostBuilder.CreateDefault(args); @@ -26,4 +28,19 @@ builder.RootComponents.Add("head::after"); builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddLocalization(options => options.ResourcesPath = "Ressources"); + +builder.Services.AddScoped, StringLocalizer>(); + +var jsInterop = builder.Build().Services.GetRequiredService(); + +var appLanguage = await jsInterop.InvokeAsync("appCulture.get"); + +if (appLanguage != null) +{ + CultureInfo cultureInfo = new CultureInfo(appLanguage); + CultureInfo.DefaultThreadCurrentCulture = cultureInfo; + CultureInfo.DefaultThreadCurrentUICulture = cultureInfo; +} + await builder.Build().RunAsync(); \ No newline at end of file diff --git a/BlazorProject/Ressources/App.Designer.cs b/BlazorProject/Ressources/App.Designer.cs new file mode 100644 index 0000000..432c94b --- /dev/null +++ b/BlazorProject/Ressources/App.Designer.cs @@ -0,0 +1,102 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace BlazorProject.Ressources { + using System; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class App { + + private static System.Resources.ResourceManager resourceMan; + + private static System.Globalization.CultureInfo resourceCulture; + + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal App() { + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager { + get { + if (object.Equals(null, resourceMan)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("BlazorProject.Ressources.App", typeof(App).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + internal static string City { + get { + return ResourceManager.GetString("City", resourceCulture); + } + } + + internal static string Gender { + get { + return ResourceManager.GetString("Gender", resourceCulture); + } + } + + internal static string Salary { + get { + return ResourceManager.GetString("Salary", resourceCulture); + } + } + + internal static string EmployeeData { + get { + return ResourceManager.GetString("EmployeeData", resourceCulture); + } + } + + internal static string Male { + get { + return ResourceManager.GetString("Male", resourceCulture); + } + } + + internal static string Female { + get { + return ResourceManager.GetString("Female", resourceCulture); + } + } + + internal static string Name { + get { + return ResourceManager.GetString("Name", resourceCulture); + } + } + + internal static string Joining_Date { + get { + return ResourceManager.GetString("Joining Date", resourceCulture); + } + } + + internal static string Save { + get { + return ResourceManager.GetString("Save", resourceCulture); + } + } + } +} diff --git a/BlazorProject/Ressources/App.fr.Designer.cs b/BlazorProject/Ressources/App.fr.Designer.cs new file mode 100644 index 0000000..58f3d77 --- /dev/null +++ b/BlazorProject/Ressources/App.fr.Designer.cs @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace BlazorProject.Ressources { + using System; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class App_fr { + + private static System.Resources.ResourceManager resourceMan; + + private static System.Globalization.CultureInfo resourceCulture; + + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal App_fr() { + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager { + get { + if (object.Equals(null, resourceMan)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("BlazorProject.Ressources.App_fr", typeof(App_fr).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + internal static string City { + get { + return ResourceManager.GetString("City", resourceCulture); + } + } + + internal static string Gender { + get { + return ResourceManager.GetString("Gender", resourceCulture); + } + } + + internal static string Salary { + get { + return ResourceManager.GetString("Salary", resourceCulture); + } + } + + internal static string EmployeeData { + get { + return ResourceManager.GetString("EmployeeData", resourceCulture); + } + } + + internal static string Male { + get { + return ResourceManager.GetString("Male", resourceCulture); + } + } + + internal static string Female { + get { + return ResourceManager.GetString("Female", resourceCulture); + } + } + + internal static string Joining_Date { + get { + return ResourceManager.GetString("Joining Date", resourceCulture); + } + } + + internal static string Name { + get { + return ResourceManager.GetString("Name", resourceCulture); + } + } + + internal static string Save { + get { + return ResourceManager.GetString("Save", resourceCulture); + } + } + + internal static string Title { + get { + return ResourceManager.GetString("Title", resourceCulture); + } + } + } +} diff --git a/BlazorProject/Ressources/App.fr.resx b/BlazorProject/Ressources/App.fr.resx new file mode 100644 index 0000000..a66c8f0 --- /dev/null +++ b/BlazorProject/Ressources/App.fr.resx @@ -0,0 +1,48 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Ville + + + Genre + + + Salaire + + + Données des employés + + + Homme + + + Femme + + + Date d'arrivée + + + Nom + + + Sauvegarder + + \ No newline at end of file diff --git a/BlazorProject/Ressources/App.resx b/BlazorProject/Ressources/App.resx new file mode 100644 index 0000000..5a52ce9 --- /dev/null +++ b/BlazorProject/Ressources/App.resx @@ -0,0 +1,48 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + City + + + Gender + + + Salary + + + EmployeeData + + + Male + + + Female + + + Name + + + Joining Date + + + Save + + \ No newline at end of file diff --git a/BlazorProject/wwwroot/index.html b/BlazorProject/wwwroot/index.html index 72e7e61..6c5177f 100644 --- a/BlazorProject/wwwroot/index.html +++ b/BlazorProject/wwwroot/index.html @@ -32,6 +32,18 @@ 🗙 + +