0

Possible Duplicate:
Getting current device language in iOS?

I need the 3 letter language ISO code as it's part of a call to another service. I can use NSLocale.CurrentLocale.Identifier to get the country code, but not language the device is set to.

Community
  • 1
  • 1
Ian Vink
  • 66,960
  • 104
  • 341
  • 555
  • You can get the two-letter country code and the two-letter language code from NSLocale but I don't know of any supplied API for getting the 3-letter version. – rmaddy Nov 06 '12 at 21:34
  • 2
    Not sure why this was closed as "Exact Dupe"? None of the questions are asking about THREE character language codes?! – Cliff Ribaudo Nov 07 '12 at 23:03

1 Answers1

1

The best you can do is:

  [[NSLocale preferredLanguages] objectAtIndex:0];

Which as per Apple docs is:

An ordered list of the user's preferred languages.

Users choose a primary language when configuring a device, as described in Reviewing Language and Region Settings. They may also specify one or more secondary languages in order of preference for use when localization is unavailable in a higher priority language. Use this property to obtain the current user's ordered list of languages, presented as an array of locale identifier strings.

You can read more about that here: IETF BCP 47

You can do the mapping yourself from what you get back to the equivalent ISO 3 letter code. There are only 47 entries in what comes back from the iOS call so not that big a deal.

Community
  • 1
  • 1
Cliff Ribaudo
  • 8,932
  • 2
  • 55
  • 78
  • This is incorrect. BCP 47 refers to a process, not the number of entries. There are around or more than some 300 entries. This answer has a better (but still out-of-date) list with code for a plist mapping: https://stackoverflow.com/questions/11576947/ios-convert-iso-alpha-2-to-alpha-3-country-code. The full list that is more reasonably up to date is on Wikipedia: https://en.wikipedia.org/wiki/ISO_3166-1 – stormont Feb 07 '19 at 06:21
  • Not sure what your point is. The answer I wrote answers the question of how to get the users preferred language. That was and is the way to do it. – Cliff Ribaudo Feb 13 '19 at 13:06