diff --git a/Blazor/Blazor/Controllers/CultureControlle.cs b/Blazor/Blazor/Controllers/CultureControlle.cs
new file mode 100644
index 0000000..26cd22e
--- /dev/null
+++ b/Blazor/Blazor/Controllers/CultureControlle.cs
@@ -0,0 +1,36 @@
+using Microsoft.AspNetCore.Localization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Blazor.Controllers
+{
+
+
+ ///
+ /// The culture controller.
+ ///
+ [Route("[controller]/[action]")]
+ public class CultureController : Controller
+ {
+ ///
+ /// Sets the culture.
+ ///
+ /// The culture.
+ /// The redirect URI.
+ ///
+ /// The action result.
+ ///
+ public IActionResult SetCulture(string culture, string redirectUri)
+ {
+ if (culture != null)
+ {
+ // Define a cookie with the selected culture
+ this.HttpContext.Response.Cookies.Append(
+ CookieRequestCultureProvider.DefaultCookieName,
+ CookieRequestCultureProvider.MakeCookieValue(
+ new RequestCulture(culture)));
+ }
+
+ return this.LocalRedirect(redirectUri);
+ }
+ }
+}
diff --git a/Blazor/Blazor/Pages/Index.razor b/Blazor/Blazor/Pages/Index.razor
index b1a9fbd..c5907d2 100644
--- a/Blazor/Blazor/Pages/Index.razor
+++ b/Blazor/Blazor/Pages/Index.razor
@@ -1,4 +1,5 @@
@page "/"
+@using System.Globalization
Index
@@ -7,3 +8,7 @@
Welcome to your new app.
+
+
+ CurrentCulture: @CultureInfo.CurrentCulture
+
diff --git a/Blazor/Blazor/Program.cs b/Blazor/Blazor/Program.cs
index 95494ac..da2e740 100644
--- a/Blazor/Blazor/Program.cs
+++ b/Blazor/Blazor/Program.cs
@@ -7,6 +7,9 @@ using Blazorise.Icons.FontAwesome;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Blazored.Modal;
+using Microsoft.AspNetCore.Localization;
+using System.Globalization;
+using Microsoft.Extensions.Options;
var builder = WebApplication.CreateBuilder(args);
@@ -26,6 +29,23 @@ builder.Services.AddScoped();
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(options =>
+{
+ // Set the default culture of the web site
+ options.DefaultRequestCulture = new RequestCulture(new CultureInfo("en-US"));
+
+ // Declare the supported culture
+ options.SupportedCultures = new List { new CultureInfo("en-US"), new CultureInfo("fr-FR") };
+ options.SupportedUICultures = new List { new CultureInfo("en-US"), new CultureInfo("fr-FR") };
+});
+
var app = builder.Build();
// Configure the HTTP request pipeline.
@@ -42,6 +62,21 @@ app.UseStaticFiles();
app.UseRouting();
+// Get the current localization options
+var options = ((IApplicationBuilder)app).ApplicationServices.GetService>();
+
+if (options?.Value != null)
+{
+ // use the default localization
+ app.UseRequestLocalization(options.Value);
+}
+
+// Add the controller to the endpoint
+app.UseEndpoints(endpoints =>
+{
+ endpoints.MapControllers();
+});
+
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
diff --git a/Blazor/Blazor/Shared/CultureSelector.razor b/Blazor/Blazor/Shared/CultureSelector.razor
new file mode 100644
index 0000000..302a9ea
--- /dev/null
+++ b/Blazor/Blazor/Shared/CultureSelector.razor
@@ -0,0 +1,43 @@
+@using System.Globalization
+@inject NavigationManager NavigationManager
+
+
+
+
+
+@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/Blazor/Blazor/Shared/MainLayout.razor b/Blazor/Blazor/Shared/MainLayout.razor
index a05118d..50acb6b 100644
--- a/Blazor/Blazor/Shared/MainLayout.razor
+++ b/Blazor/Blazor/Shared/MainLayout.razor
@@ -10,6 +10,9 @@