5

Is it possible to get the actual language of the OS like on Windows Phone? I'm using CultureInfo.CurrentCulture.TwoLetterIsoString, but I recieve always en and not the right language, which is de in my case.

So how can I get the actual language in a WinRT app?

Bart
  • 9,925
  • 7
  • 47
  • 64

7 Answers7

26

There are actually many "kind-of wrong" answers to this.

  • Windows.Globalization.Language.CurrentInputMethodLanguageTag as pointed out by Thomas will not work in all the scenarios. It only returns the language in which user's keyboard is displayed.
  • You can also use Windows.Globalization.ApplicationLanguages.Languages but it is a combination of user language preference and applications supported languages.

For most acurate user preference language, You'll need to use Windows.System.UserProfile.GlobalizationPreferences.Languages[0].

Avi
  • 2,373
  • 17
  • 22
4

You can use

Windows.Globalization.Language.CurrentInputMethodLanguageTag

to get the actual language. It returns for example de-DE, if you are using a german verison of Windows 8.

  • 1
    Actually, that returns the current keyboard language, not the user Regional Settings selection! WinRT doesn't have a direct equivalent to CurrentCulture, but `Windows.Globalization` namespace does provide alternatives to it! – Pedro Lamas Oct 30 '15 at 20:41
  • My keyboard layout does not reflect my preferred language. This is common when you belong to a local minority (as actually the majority of the people of the world do), and when you prefer English as the system language because you interact internationally. – tripleee Dec 14 '20 at 04:48
2

According to MSDN the correct answer is:

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

This should be user's most preferred language.

tripleee
  • 175,061
  • 34
  • 275
  • 318
miro smelko
  • 139
  • 6
1

As far as I remember:

Windows.Globalization.ApplicationPreferences.PreferredLanguage
EgorBo
  • 6,120
  • 3
  • 35
  • 40
1

If you create a HTML5/javascript Windows App. You can use this:

var language = window.navigator.userLanguage || window.navigator.language;
alert(language);
user1731468
  • 864
  • 2
  • 9
  • 30
0
String topUserLanguage = GlobalizationPreferences.Languages[0];
Windows.Globalization.Language userLanguage = new Windows.Globalization.Language(topUserLanguage);

if (userLanguage.Script.Equals("Arab") || userLanguage.Script.Equals("Hebr"))
{
....................
}
tripleee
  • 175,061
  • 34
  • 275
  • 318
psw
  • 29
  • 2