Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get actual system culture info

I have an UWP app for Windows 10 Mobile. The app currently offers two languages - English (en-US) and Czech (cs-CZ). The issue I'm having is that when a user for example from Spain uses the app, the date and time formats are American, not Spanish (the default app language is en-US):

DateTime.Now.ToString("d", System.Globalization.CultureInfo.CurrentCulture);
DateTime.Now.ToString("d", System.Globalization.CultureInfo.CurrentUICulture);
DateTime.Now.ToString(System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortDatePattern);

I would like to somehow obtain the ACTUAL system language to have the dates and times in the correct format based on the phone language. Currently, it looks like all the APIs from System.Globalization namespace return the culture info the app is using.

like image 678
Honza Kalfus Avatar asked Oct 27 '25 19:10

Honza Kalfus


1 Answers

After more searching, I've managed to come across the following question: Date Time formatting in Windows 10 Universals (Store) Apps where the author of the question mentions the following API call:

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

This returns the language string for the first language from the user's system preferences language list.

Using it in the following way gives me the expected result:

DateTime.Now.ToString("d", new System.Globalization.CultureInfo(Windows.System.UserProfile.GlobalizationPreferences.Languages[0]));
like image 176
Honza Kalfus Avatar answered Oct 29 '25 07:10

Honza Kalfus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!