4

On an iPhone, when the user sets their Language to French and their Region Format to United States, the CurrentCulture represents en-US.

Only when the user sets their Region Format to France do I get fr-FR;

How can I determine the language if the user has set their Langauge, but not their Region Format?

enter image description here

Ian Vink
  • 66,960
  • 104
  • 341
  • 555

2 Answers2

5

You want to look at NSLocale, e.g. NSLocale.CurrentLocale.Identifier to get a string like en-US. That will give you the exact values that iOS is using.

Both .NET and iOS have similar, but subtly different, API to get those values. It's difficult to be fully compatible with .NET by using only iOS data (it's not a perfect fit). In some case, e.g. RegionInfo, we have been able to bootstrap the .NET classes using iOS provided data. As more features becomes available we might be able to do the same for other types in the future.

poupou
  • 43,413
  • 6
  • 77
  • 174
  • I use your solution, but It keeps getting me "en_US", even when I have set the language to Spanish, but the regional format to United States, how do I get the language?, I´m using xamarin. – Guillermo Oramas R. May 27 '13 at 16:12
  • THis gives me the 3 letter language code fairly well I have since found. Set the Region Format in the Settings app to Korean to get "KOR" for example: iSOLanguage = System.Globalization.CultureInfo.CurrentCulture.ThreeLetterISOLanguageName.ToUpper () – Ian Vink Nov 23 '13 at 18:45
0

NSLocale.CurrentLocale gives the region format, not the language.

To get the language, use NSLocale.PreferredLanguages[0] instead. The result will be a string like fr or en-US for the language that is selected.

For more info, see Getting current device language in iOS?.

Community
  • 1
  • 1
Geir Sagberg
  • 9,632
  • 8
  • 45
  • 60