Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Configure CurrentCulture according to working language
support101a134991e6
diff --git a/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs b/src/Core/Grand.Infrastructure/Configuration/AppConfig.csindex fe4248337..3687f4331 100644--- a/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs+++ b/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs@@ -5,11 +5,6 @@ namespace Grand.Infrastructure.Configuration/// </summary>public class AppConfig{- public AppConfig()- {- SupportedCultures = new List<string>();- }-/// <summary>/// Indicates whether we should Disable HostedService - BackgroundServiceTask/// </summary>@@ -37,12 +32,6 @@ namespace Grand.Infrastructure.Configuration/// </summary>public bool DisplayFullErrorStack { get; set; }public bool UseSessionStateTempDataProvider { get; set; }- /// <summary>- /// Localization middleware- /// </summary>- public bool UseRequestLocalization { get; set; }- public string DefaultRequestCulture { get; set; }- public IList<string> SupportedCultures { get; set; }/// <summary>/// Gets or sets a value custom response header encoding may be needed in some casesdiff --git a/src/Web/Grand.Web.Admin/App_Data/appsettings.json b/src/Web/Grand.Web.Admin/App_Data/appsettings.jsonindex 5b610ceb5..d5754c15e 100644--- a/src/Web/Grand.Web.Admin/App_Data/appsettings.json+++ b/src/Web/Grand.Web.Admin/App_Data/appsettings.json@@ -12,12 +12,7 @@//Enable the session-based TempData provider"UseSessionStateTempDataProvider": false,-- //Use my request localization culture- "UseRequestLocalization": false,- "DefaultRequestCulture": "en-US",- "SupportedCultures": [ "en-US", "pl-PL" ], //sample list-+//Indicates whether to disable hosted service - BackgroundServiceTask"DisableHostedService": false,diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/Date.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/Date.cshtmlindex b61d3d8a2..901898509 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/Date.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/Date.cshtml@@ -1,10 +1,9 @@@model DateTime-@using System.Globalization-<input id="@Html.IdForModel()" name="@Html.NameForModel()" value="@((Model > DateTime.MinValue ? Model : DateTime.Today).ToString(CultureInfo.CurrentCulture.DateTimeFormat.UniversalSortableDateTimePattern))" />+<input asp-for="@Model"/><script>$(document).ready(function () {$("#@Html.IdForModel()").kendoDatePicker({- //culture: "@CultureInfo.CurrentCulture.Name"+ culture: "@CultureInfo.CurrentCulture.Name"});});</script>\ No newline at end of filediff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DateNullable.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DateNullable.cshtmlindex 4107099bd..19a14fe9f 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DateNullable.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DateNullable.cshtml@@ -1,10 +1,9 @@@model DateTime?-@using System.Globalization-<input id="@Html.IdForModel()" name="@Html.NameForModel()" value="@(Model > DateTime.MinValue ? Model.Value.ToString(CultureInfo.CurrentCulture.DateTimeFormat.UniversalSortableDateTimePattern) : "")" />+<input asp-for="@Model"/><script>$(document).ready(function () {$("#@Html.IdForModel()").kendoDatePicker({- //culture: "@CultureInfo.CurrentCulture.Name"+ culture: "@CultureInfo.CurrentCulture.Name"});});</script>\ No newline at end of filediff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DateTime.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DateTime.cshtmlindex 969c2acc4..7a71fea21 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DateTime.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DateTime.cshtml@@ -1,9 +1,10 @@@model DateTime-<input id="@Html.IdForModel()" name="@Html.NameForModel()" value="@((Model > DateTime.MinValue ? Model : DateTime.Today).ToString("M/d/yyyy h:mm:ss tt"))" />+<input id="@Html.IdForModel()" name="@Html.NameForModel()" value="@(Model)" />+<script>$(document).ready(function () {$("#@Html.IdForModel()").kendoDateTimePicker({- parseFormats: ["M/d/yyyy h:mm:ss tt"],+ culture: "@CultureInfo.CurrentCulture.Name"});});</script>\ No newline at end of filediff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DateTimeNullable.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DateTimeNullable.cshtmlindex 9b5dda4da..a65bd8e8f 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DateTimeNullable.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DateTimeNullable.cshtml@@ -1,9 +1,9 @@@model DateTime?-<input id="@Html.IdForModel()" name="@Html.NameForModel()" value="@(Model > DateTime.MinValue || Model.HasValue ? Model.Value.ToString("M/d/yyyy h:mm:ss tt") : "")" />+<input id="@Html.IdForModel()" name="@Html.NameForModel()" value="@(Model.HasValue ? Model.Value : "")" /><script>$(document).ready(function () {$("#@Html.IdForModel()").kendoDateTimePicker({- parseFormats: ["M/d/yyyy h:mm:ss tt"],+ culture: "@CultureInfo.CurrentCulture.Name"});});-</script>\ No newline at end of file+</script>diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/Decimal.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/Decimal.cshtmlindex 650640e63..0080118bc 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/Decimal.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/Decimal.cshtml@@ -1,11 +1,15 @@@model decimal[email protected](model => model)-@using System.Globalization+<input asp-for="@Model"/><script>$(document).ready(function() {+ try {+ $("#@Html.IdForModel()").rules("remove", 'number');+ }+ catch {}$("#@Html.IdForModel()").kendoNumericTextBox({- culture: "@CultureInfo.CurrentCulture.Name",- format: "n2",+ culture: "@CultureInfo.CurrentCulture.Name",+ format: 'n2',+ decimals: 2});});</script>diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DecimalN4.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DecimalN4.cshtmlindex 5d8c31b3d..cbf04194e 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DecimalN4.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DecimalN4.cshtml@@ -1,8 +1,11 @@@model decimal[email protected](model => model)-@using System.Globalization+<input asp-for="@Model"/><script>$(document).ready(function() {+ try {+ $("#@Html.IdForModel()").rules("remove", 'number');+ }+ catch {}$("#@Html.IdForModel()").kendoNumericTextBox({culture: "@CultureInfo.CurrentCulture.Name",format: 'n4',diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DecimalNullable.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DecimalNullable.cshtmlindex 3c0ad6ae4..3d9877a22 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DecimalNullable.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DecimalNullable.cshtml@@ -1,11 +1,15 @@@model decimal?[email protected](model => model)-@using System.Globalization+<input asp-for="@Model"/><script>$(document).ready(function () {+ try {+ $("#@Html.IdForModel()").rules("remove", 'number');+ }+ catch {}$("#@Html.IdForModel()").kendoNumericTextBox({culture: "@CultureInfo.CurrentCulture.Name",- format: "n2",+ format: 'n2',+ decimals: 2});});</script>\ No newline at end of filediff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/Double.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/Double.cshtmlindex b1192125a..81c10a938 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/Double.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/Double.cshtml@@ -1,11 +1,15 @@@model double[email protected](model => model)-+<input asp-for="@Model"/><script>$(document).ready(function () {- $("#@Html.IdForModel()").kendoNumericTextBox({- format: "0.############",- decimals: 12,+ try {+ $("#@Html.IdForModel()").rules("remove", 'number');+ }+ catch {}+ $("#@Html.IdForModel()").kendoNumericTextBox({+ culture: "@CultureInfo.CurrentCulture.Name",+ format: 'n2',+ decimals: 2});});</script>diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DoubleN4.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DoubleN4.cshtmlindex e67d1702b..409b3f0de 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DoubleN4.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DoubleN4.cshtml@@ -1,6 +1,5 @@@model double[email protected](model => model)-@using System.Globalization+<input asp-for="@Model"/><script>$(document).ready(function() {$("#@Html.IdForModel()").kendoNumericTextBox({diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DoubleNullable.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DoubleNullable.cshtmlindex 5b1949395..f4cfbee15 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DoubleNullable.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/DoubleNullable.cshtml@@ -1,11 +1,11 @@@model double?[email protected](model => model)-@using System.Globalization+<input asp-for="@Model"/><script>$(document).ready(function () {$("#@Html.IdForModel()").kendoNumericTextBox({culture: "@CultureInfo.CurrentCulture.Name",- format: "n2",+ format: 'n2',+ decimals: 2});});</script>\ No newline at end of filediff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/Partials/HeadAdmin.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/Partials/HeadAdmin.cshtmlindex c6e137c10..84dd6c8f9 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/Partials/HeadAdmin.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/Partials/HeadAdmin.cshtml@@ -46,7 +46,7 @@<script asp-location="Head" asp-src="@(Common.WwwRoot)/administration/admin.common.js"></script><script asp-location="Head" asp-src="@string.Format(Common.WwwRoot+"/administration/kendo/scripts/{0}/kendo.ui.core.min.js", kendoVersion)"></script><script asp-location="Head" asp-src="@string.Format(Common.WwwRoot+"/administration/kendo/scripts/{0}/kendo.grid.js", kendoVersion)"></script>- <script asp-location="Head" asp-src="@string.Format(Common.WwwRoot+"/administration/kendo/scripts/{0}/cultures/kendo.culture.{1}.min.js", kendoVersion, "en-US" )"></script>+ <script asp-location="Head" asp-src="@string.Format(Common.WwwRoot+"/administration/kendo/scripts/{0}/cultures/kendo.culture.{1}.js", kendoVersion, @CultureInfo.CurrentCulture.Name)"></script><script asp-location="Footer" asp-src="@(Common.WwwRoot)/administration/bootstrap/js/popper.min.js"></script>diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/_AdminLayout.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/_AdminLayout.cshtmlindex 924516ea8..9af926d66 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/_AdminLayout.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/_AdminLayout.cshtml@@ -41,6 +41,7 @@<body class="nav-sm @if (IsSectionDefined("popupwindow")) { @await RenderSectionAsync("popupwindow") <text>no-sidebar</text> }">@Html.AntiForgeryToken()<script>+ kendo.culture("@CultureInfo.CurrentCulture.Name");if (document.readyState == "loading") {$(".site_title").css("padding-left", "26px");if ($('body').hasClass('nav-sm')) {diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/_ViewImports.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/_ViewImports.cshtmlindex a96544070..7787e703b 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/_ViewImports.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/_ViewImports.cshtml@@ -3,6 +3,7 @@@addTagHelper *, Grand.Web.Admin@addTagHelper *, Grand.Web+@using System.Globalization@using Microsoft.AspNetCore.Http.Extensions@using Microsoft.AspNetCore.Mvc.ViewFeatures@using System.Textdiff --git a/src/Web/Grand.Web.Admin/Grand.Web.Admin.csproj b/src/Web/Grand.Web.Admin/Grand.Web.Admin.csprojindex 7ffb6c0b0..216542664 100644--- a/src/Web/Grand.Web.Admin/Grand.Web.Admin.csproj+++ b/src/Web/Grand.Web.Admin/Grand.Web.Admin.csproj@@ -6,7 +6,7 @@<EnableDefaultContentItems>false</EnableDefaultContentItems><UseAppHost>false</UseAppHost><!--Set GenerateRuntimeConfigurationFiles as true when Admin panel is supposed to works independent-->- <GenerateRuntimeConfigurationFiles>false</GenerateRuntimeConfigurationFiles>+ <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles></PropertyGroup><ItemGroup><Content Include="Areas\**" CopyToPublishDirectory="Never" />diff --git a/src/Web/Grand.Web.Common/Middleware/CultureSettingMiddleware.cs b/src/Web/Grand.Web.Common/Middleware/CultureSettingMiddleware.csnew file mode 100644index 000000000..25f2c6b18--- /dev/null+++ b/src/Web/Grand.Web.Common/Middleware/CultureSettingMiddleware.cs@@ -0,0 +1,34 @@+using Grand.Infrastructure;+using Microsoft.AspNetCore.Http;+using System.Globalization;++namespace Grand.Web.Common.Middleware;++public class CultureSettingMiddleware+{+ private readonly RequestDelegate _next;++ public CultureSettingMiddleware(RequestDelegate next)+ {+ _next = next;+ }++ public async Task InvokeAsync(HttpContext context, IWorkContext workContext)+ {+ if (workContext.WorkingLanguage != null)+ {+ var culture = new CultureInfo(workContext.WorkingLanguage.LanguageCulture);++ CultureInfo.CurrentCulture = culture;+ CultureInfo.CurrentUICulture = culture;+ }+ else+ {+ var culture = new CultureInfo("en-US");+ CultureInfo.CurrentCulture = culture;+ CultureInfo.CurrentUICulture = culture;+ }++ await _next(context);+ }+}\ No newline at end of filediff --git a/src/Web/Grand.Web.Common/Middleware/WorkContextMiddleware.cs b/src/Web/Grand.Web.Common/Middleware/WorkContextMiddleware.csindex 4362bd991..801cfe191 100644--- a/src/Web/Grand.Web.Common/Middleware/WorkContextMiddleware.cs+++ b/src/Web/Grand.Web.Common/Middleware/WorkContextMiddleware.cs@@ -33,7 +33,7 @@ namespace Grand.Web.Common.Middleware/// <param name="context">HTTP context</param>/// <param name="workContext">workContext</param>/// <returns>Task</returns>- public async Task Invoke(HttpContext context, IWorkContext workContext)+ public async Task InvokeAsync(HttpContext context, IWorkContext workContext){if (context?.Request == null){@@ -43,27 +43,10 @@ namespace Grand.Web.Common.Middleware//set current contextvar customer = await workContext.SetCurrentCustomer();await workContext.SetCurrentVendor(customer);- var language = await workContext.SetWorkingLanguage(customer);+ _ = await workContext.SetWorkingLanguage(customer);await workContext.SetWorkingCurrency(customer);await workContext.SetTaxDisplayType(customer);- //set culture in admin area- if (context.Request.Path.Value != null && context.Request.Path.Value.StartsWith("/admin", StringComparison.InvariantCultureIgnoreCase))- {- var culture = new CultureInfo("en-US");- CultureInfo.CurrentCulture = culture;- CultureInfo.CurrentUICulture = culture;- }- else- {- //set culture for customer- if (!string.IsNullOrEmpty(language?.LanguageCulture))- {- var culture = new CultureInfo(language.LanguageCulture);- CultureInfo.CurrentCulture = culture;- CultureInfo.CurrentUICulture = culture;- }- }//call the next middleware in the request pipelineawait _next(context);}diff --git a/src/Web/Grand.Web.Common/Startup/AuthenticationStartup.cs b/src/Web/Grand.Web.Common/Startup/AuthenticationStartup.csindex a2c01bcfe..789739430 100644--- a/src/Web/Grand.Web.Common/Startup/AuthenticationStartup.cs+++ b/src/Web/Grand.Web.Common/Startup/AuthenticationStartup.cs@@ -45,6 +45,8 @@ namespace Grand.Web.Common.Startup//set work contextapplication.UseMiddleware<WorkContextMiddleware>();+ //set culture+ application.UseMiddleware<CultureSettingMiddleware>();}diff --git a/src/Web/Grand.Web.Common/Startup/GrandCommonStartup.cs b/src/Web/Grand.Web.Common/Startup/GrandCommonStartup.csindex 33db963a8..4027d76d8 100644--- a/src/Web/Grand.Web.Common/Startup/GrandCommonStartup.cs+++ b/src/Web/Grand.Web.Common/Startup/GrandCommonStartup.cs@@ -108,22 +108,7 @@ namespace Grand.Web.Common.Startup{application.UseHtmlMinification();}-- //use request localization- if (appConfig.UseRequestLocalization)- {- var supportedCultures = appConfig.SupportedCultures.Select(culture => new CultureInfo(culture)).ToList();- application.UseRequestLocalization(new RequestLocalizationOptions- {- DefaultRequestCulture = new RequestCulture(appConfig.DefaultRequestCulture),- SupportedCultures = supportedCultures,- SupportedUICultures = supportedCultures- });- }- else- //use default request localization- application.UseRequestLocalization();-+//use static files featureapplication.UseGrandStaticFiles(appConfig);diff --git a/src/Web/Grand.Web/App_Data/appsettings.json b/src/Web/Grand.Web/App_Data/appsettings.jsonindex 97ab11fc7..931101e36 100644--- a/src/Web/Grand.Web/App_Data/appsettings.json+++ b/src/Web/Grand.Web/App_Data/appsettings.json@@ -17,11 +17,6 @@"SeoFriendlyUrlsForLanguagesEnabled": false,"SeoFriendlyUrlsDefaultCode": "en",- //Use my request localization culture- "UseRequestLocalization": false,- "DefaultRequestCulture": "en-US",- "SupportedCultures": [ "en-US", "pl-PL" ], //sample list-//Indicates whether to disable hosted service - BackgroundServiceTask"DisableHostedService": false,