How to set CultureInfo.CurrentCulture?
Asked Answered
T

4

10

Using:

Console.WriteLine(System.Globalization.CultureInfo.CurrentCulture.ToString());

I get "en-US".

What should I change in my control panel settings ( Region and Language ? ) to get something else for example "en-CA" .

Twodimensional answered 23/1, 2014 at 17:50 Comment(6)
What's the context? What kind of app is this?Abysm
Duplicate of #9698104 , your answer is in the linked question.Wulfila
@LouisvanTonder, he is not writing an MVC application, his issue is with a console application. Not a duplicate as it doesn't applyCredulity
@JonSkeet It is a Silverlight app, When I go to regional and language setting I can change the short date format and then I can see the result of my change if I call "CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern" So I was wondering what I change there to be able to call something similar in C# side to see "en-CA" for example? if possible at allTwodimensional
@AnthonyShaw , "What should I change in my control panel settings ( Region and Language ? ) "Wulfila
Just a small hint from my own experience: in the windows region control panel, I had to set the regional format to the explicit value instead of the «recommended» option before CurrentCulture became what I was expecting it to beTauten
C
5

In my experience, the culture was set by the version of the operating system. Not really a setting in the control panel. We used to have to have multiple VM's running multiple version of Windows to test our cultural based features

Credulity answered 23/1, 2014 at 17:54 Comment(1)
oh ok thanks, I thought it is similar to when we change date time formats in there, I thought there is something for culture too.Twodimensional
R
15

What should I change in my control panel settings ( Region and Language ? ) to get something else for example "en-CA" .

You can change it for current thread like:

System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-CA");

and then:

Console.WriteLine(System.Globalization.CultureInfo.CurrentCulture.ToString());

would return:

en-CA
Rummel answered 23/1, 2014 at 17:53 Comment(0)
C
5

In my experience, the culture was set by the version of the operating system. Not really a setting in the control panel. We used to have to have multiple VM's running multiple version of Windows to test our cultural based features

Credulity answered 23/1, 2014 at 17:54 Comment(1)
oh ok thanks, I thought it is similar to when we change date time formats in there, I thought there is something for culture too.Twodimensional
G
1

you could just define a key in your App.config like this

<configuration>
    <appSettings>
        <add key="DefaultCulture" value="en-CA" />
    </appSettings>
</configuration>

and in your application read that value and set the culture

 CultureInfo culture = new CultureInfo(ConfigurationManager.AppSettings["DefaultCulture"]);
    Thread.CurrentThread.CurrentCulture = culture;
    Thread.CurrentThread.CurrentUICulture = culture;
Gradin answered 23/1, 2014 at 18:38 Comment(0)
C
1

You can change the language in the Region and Language control panel. Choose English (Canada) from the drop-down combo box labeled Format. Note that this will apply for the user and is the User Locale.

As a side note, starting with Windows 8, the user locale defaults to whatever your Windows display language is and Windows Store apps make use of the language list to align the language that is used for producing date and time strings and number formatting, etc., with the language that is used for retrieving resources. .Net attempts to participate in this, so for Windows Store Apps, changing the language list is the preferred way to get this effect.

Cutch answered 23/1, 2014 at 23:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.