diff --git a/Oqtane.Server/Oqtane.Server.csproj b/Oqtane.Server/Oqtane.Server.csproj index 44237543..31523442 100644 --- a/Oqtane.Server/Oqtane.Server.csproj +++ b/Oqtane.Server/Oqtane.Server.csproj @@ -43,6 +43,7 @@ + diff --git a/Oqtane.Server/Pages/_Host.cshtml b/Oqtane.Server/Pages/_Host.cshtml index 0fe00957..e4b6e5a7 100644 --- a/Oqtane.Server/Pages/_Host.cshtml +++ b/Oqtane.Server/Pages/_Host.cshtml @@ -1,10 +1,17 @@ @page "/" @namespace Oqtane.Pages @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@using System.Globalization +@using Microsoft.AspNetCore.Localization @using Microsoft.Extensions.Configuration @inject IConfiguration Configuration @model Oqtane.Pages.HostModel +@{ + // Set localization cookie + var localizationCookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(CultureInfo.CurrentCulture, CultureInfo.CurrentUICulture)); + HttpContext.Response.Cookies.Append(CookieRequestCultureProvider.DefaultCookieName, localizationCookieValue); +} diff --git a/Oqtane.Server/Startup.cs b/Oqtane.Server/Startup.cs index f70397bb..7de3eceb 100644 --- a/Oqtane.Server/Startup.cs +++ b/Oqtane.Server/Startup.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.IO; using System.Linq; using System.Net.Http; @@ -16,6 +17,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.OpenApi.Models; using Oqtane.Extensions; using Oqtane.Infrastructure; +using Oqtane.Infrastructure.Localization; using Oqtane.Repository; using Oqtane.Security; using Oqtane.Services; @@ -51,6 +53,10 @@ namespace Oqtane // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { + // Register localization services + services.AddLocalization(options => options.ResourcesPath = "Resources"); + CultureInfo.CurrentUICulture = new CultureInfo(LocalizationSettings.DefaultCulture); + services.AddServerSideBlazor(); // setup HttpClient for server side in a client side compatible fashion ( with auth cookie ) @@ -225,6 +231,10 @@ namespace Oqtane } // to allow install middleware it should be moved up app.ConfigureOqtaneAssemblies(env); + + app.UseRequestLocalization(options => options + .AddSupportedUICultures(LocalizationSettings.SupportedCultures.ToArray())); + app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseBlazorFrameworkFiles();