Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor WebAssembly not applying culture to DateTime formatting after changing culture

$
0
0

I recently migrated my Blazor project from Blazor Server to Blazor WebAssembly. In the Blazor Server version, when I changed the culture (e.g., CultureInfo.CurrentUICulture = new CultureInfo("fa-IR")), both the localized texts from .resx files andDateTime formatting would update accordingly.

However, in Blazor WebAssembly, when I change the culture at runtime using:

var cookieService = app.Services.GetRequiredService<CookieService>();var cookieValue = CookieService.ParseAspNetCoreCultureCookie(await cookieService.GetCookieAsync(".AspNetCore.Culture"));if (string.IsNullOrEmpty(cookieValue)){    var cultureInfo = new CultureInfo(GlobalSettings.Languages.FirstOrDefault().ToString());    CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;}else    CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(cookieValue);CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en");await app.RunAsync();aultThreadCurrentCulture = new CultureInfo("fa-IR");CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("fa-IR");

the text resources update correctly, but DateTime.ToString() formatting still uses the default en-US format.

It seems like DateTime formatting is not picking up the new culture in WebAssembly.

How can I make DateTime formatting respect the new culture at runtime in Blazor WebAssembly, just like it does in Blazor Server?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>