Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting current culture for entire solution

I'm trying to support multiple languages in a solution that has multiple projects and threads.

I have 2 resource files, one with English strings, and one with French strings.

I'm setting the current culture as follows:

Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(isEnglish ? "en-US" : "fr-CA");

Is there a way to set the current culture globally, for the entire solution, or do I have to do this for each thread that needs to access strings?

like image 335
NMunro Avatar asked Dec 18 '12 15:12

NMunro


People also ask

How do you change the current UI culture?

To change the current UI culture, you assign the CultureInfo object that represents the new UI culture to the Thread. CurrentThread. CurrentUICulture property.

What is CultureInfo InvariantCulture in C#?

The CultureInfo. InvariantCulture property is used if you are formatting or parsing a string that should be parseable by a piece of software independent of the user's local settings. The default value is CultureInfo. InstalledUICulture so the default CultureInfo is depending on the executing OS's settings.

How do you set CultureInfo InvariantCulture?

You specify the invariant culture by name by using an empty string ("") in the call to a CultureInfo instantiation method. CultureInfo. InvariantCulture also retrieves an instance of the invariant culture. It can be used in almost any method in the System.

What is UICulture?

In an ASP.NET Web page, you can set to two culture values, the Culture and UICulture properties. The Culture value determines the results of culture-dependent functions, such as the date, number, and currency formatting, and so on. The UICulture value determines which resources are loaded for the page.


2 Answers

In .NET Framework 4.5, the CultureInfo.DefaultThreadCurrentCulture Property gets or sets the default culture for threads in the current application domain.

In the .NET Framework 4 and previous versions, by default, the culture of all threads is set to the Windows system culture. For applications whose current culture differs from the default system culture, this behavior is often undesirable. In the .NET Framework 4.5, the DefaultThreadCurrentCulture property enables an application to define the default culture of all threads in an application domain.

like image 145
Alex Filipovici Avatar answered Oct 20 '22 01:10

Alex Filipovici


You can add a globalization section within system.Web in the web.config

<globalization culture="en-US" uiCulture="en-US" />
like image 25
levelnis Avatar answered Oct 20 '22 01:10

levelnis