diff --git a/WF-WebAdmin/WF-WebAdmin/Controllers/CultureController.cs b/WF-WebAdmin/WF-WebAdmin/Controllers/CultureController.cs
new file mode 100644
index 0000000..8f8cfec
--- /dev/null
+++ b/WF-WebAdmin/WF-WebAdmin/Controllers/CultureController.cs
@@ -0,0 +1,31 @@
+using Microsoft.AspNetCore.Localization;
+using Microsoft.AspNetCore.Mvc;
+
+///
Indice de connexion : admin / admin
- ++ CurrentCulture: @CultureInfo.CurrentCulture +
@code { diff --git a/WF-WebAdmin/WF-WebAdmin/Program.cs b/WF-WebAdmin/WF-WebAdmin/Program.cs index fb07a82..2e00bd1 100644 --- a/WF-WebAdmin/WF-WebAdmin/Program.cs +++ b/WF-WebAdmin/WF-WebAdmin/Program.cs @@ -3,9 +3,13 @@ using Blazorise.Bootstrap; using Blazorise.Icons.FontAwesome; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; +using Microsoft.AspNetCore.Localization; +using System.Globalization; using WF_WebAdmin.Data; using WF_WebAdmin.Model; - +using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; +using Blazored.Modal; var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -22,6 +26,25 @@ builder.Services .AddHttpClient() .AddFontAwesomeIcons(); + +builder.Services.AddBlazoredModal(); +// Add the controller of the app +builder.Services.AddControllers(); + +// Add the localization to the app and specify the resources path +builder.Services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; }); + +// Configure the localtization +builder.Services.Configure+ +
+ +@code +{ + private CultureInfo[] supportedCultures = new[] + { + new CultureInfo("en-US"), + new CultureInfo("fr-FR") + }; + + private CultureInfo Culture + { + get => CultureInfo.CurrentCulture; + set + { + if (CultureInfo.CurrentUICulture == value) + { + return; + } + + var culture = value.Name.ToLower(CultureInfo.InvariantCulture); + + var uri = new Uri(this.NavigationManager.Uri).GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped); + var query = $"?culture={Uri.EscapeDataString(culture)}&" + $"redirectUri={Uri.EscapeDataString(uri)}"; + + // Redirect the user to the culture controller to set the cookie + this.NavigationManager.NavigateTo("/Culture/SetCulture" + query, forceLoad: true); + } + } +} \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Shared/MainLayout.razor b/WF-WebAdmin/WF-WebAdmin/Shared/MainLayout.razor index d62d291..eab28e1 100644 --- a/WF-WebAdmin/WF-WebAdmin/Shared/MainLayout.razor +++ b/WF-WebAdmin/WF-WebAdmin/Shared/MainLayout.razor @@ -15,6 +15,9 @@