Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How can I set the language of Localizer by code in blazor server-side?

$
0
0

I need to embed a Blazor server-side component to an existing asp.net core project.

I followed the tutorial of this https://medium.com/@geobourno/bringing-blazor-in-an-existing-net-core-mvc-project-d605d9f9ebe8 by creating a brand new blazer server-side project in the same solution.

All works well.

Now I added the Localizer to the blazor server-side project and want to set the language of its Localizer the same as the asp.net core project(the asp.net core project is choosing the language by URL just ashttps://www.microsoft.com/en-us/).

Meanwhile, the blazor only set its language the same as the browser while running.

I think I should set a parameter(which to record the language type) of blazor component in asp.net core first. After blazor runs, it gets the parameter and set the language the same as it.

I don't know whether my idea is right but I just want to set the language of its Localizer the same as the asp.net core project dynamically.

PS:

Someone tells me to achieve it like this in OnAfterRenderAsync of blazor:

CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("zh-hant");
CultureInfo.CurrentCulture = new CultureInfo("zh-hant");
CultureInfo.CurrentUICulture = new CultureInfo("zh-hant");

Well, it doesn't work any.

How can I solve this? Thank you.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



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