How to force culture in asp.net?

I want to be able to set culture at runtime. For instance:

protected void Page_Load(object sender, EventArgs e) { Page.Culture = "fr-FR"; Page.UICulture = "fr"; } 

But this has no effect. I use resource files for translation. If I change the language of my browser, it works fine, but I want the user to be able to choose the language as well. Therefore, in this case, the user wants the language to be French.

Any ideas? I am lost.

+4
source share
3 answers

If you create a site on which you allow the user, for example, to change the language, you need to execute it in the Global.asax file in the Application_BeginRequest method.

Each request will have a culture set.

You simply set the following two lines:

  Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-FR"); Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR"); 

The first line will indicate the formatting of the number / date / etc.

The second line indicates which localization of resources to load - which will contain the translated content.

+15
source

You can try:

  Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); 

See the MSDN article for more details.

+3
source
  • If you want to install it for the entire application, you can install it in Global.asax as

    Thread.Current.Culture = New System.Globalization.CultureInfo ("fr-FR");

+1
source

Source: https://habr.com/ru/post/1485675/


All Articles