testing
testing

Reputation: 20279

UWP: Get current CultureInfo

For UWP there are some changes in the CultureInfo according to the blog entry CultureInfo changes in UWP. Can I take GlobalizationPreferences to get the CultureInfo correctly?

public CultureInfo GetCurrentCultureInfo()
{
    return new CultureInfo(Windows.System.UserProfile.GlobalizationPreferences.Languages[0].ToString());
}

Taken from this example.

Upvotes: 6

Views: 4889

Answers (2)

Pedro Lamas
Pedro Lamas

Reputation: 7233

If what you require is the "correct" CultureInfo (the one taking into account the user/machine regional settings), then you should either use the information on that blog post, or even better, use the GetLocaleInfoEx Win32 API to retrive it.

I've written a Part 2 of that article that includes a complete example of how to use this API.

Upvotes: 5

Grace Feng
Grace Feng

Reputation: 16652

Can I take GlobalizationPreferences to get the CultureInfo correctly?

Yes you can, I've tested your method, it works well by my side.

I want to know the current language of the device (not region).

You can also use Windows.Globalization.Language.CurrentInputMethodLanguageTag to get the current enabled keyboard layout or Input.

Upvotes: 5

Related Questions