Sharpeye500
Sharpeye500

Reputation: 9071

Get current language in CultureInfo

How to identify the operating system's language using CultureInfo? E.g. if the language in Windows is set to French, I need to identify French and load the fr resource files data.

Upvotes: 76

Views: 141203

Answers (6)

RTDev
RTDev

Reputation: 866

Windows.System.UserProfile.GlobalizationPreferences.Languages[0]

This is the correct way to obtain the currently set system language. System language setting is completely different than culture setting from which you all want to get the language.

For example: User may use "en-GB" language along with "en-US" culture at the same time. Using CurrentCulture and other cultures you will get "en-US", hope you get the difference (that may be innoticable with GB-US, but with other languages?)

Upvotes: 2

primehunter
primehunter

Reputation: 300

To get the 2 chars ISO 639-1 language identifier use:

System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;

Upvotes: 7

Leonardo Alves Machado
Leonardo Alves Machado

Reputation: 2837

I tried {CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;} but it didn`t work for me, since my UI culture was different from my number/currency culture. So I suggest you to use:

CultureInfo currentCulture = Thread.CurrentThread.CurrentUICulture;

This will give you the culture your UI is (texts on windows, message boxes, etc).

Upvotes: 8

smukamuka
smukamuka

Reputation: 1537

This is what i used:

var culture = System.Globalization.CultureInfo.CurrentCulture;

and it's working :)

Upvotes: 38

DominicusPlatus
DominicusPlatus

Reputation: 139

Current system language is retrieved using :

  CultureInfo.InstalledUICulture

"Gets the CultureInfo that represents the culture installed with the operating system."

InstalledUICulture

To set it as default language for thread use :

   System.Globalization.CultureInfo.DefaultThreadCurrentCulture=CultureInfo.InstalledUICulture;

Upvotes: 11

Brosto
Brosto

Reputation: 4565

I think something like this would give you the current CultureInfo:

CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;

Is that what you're looking for?

Upvotes: 100

Related Questions