8

Starting from iOS 11.0, the following code returns "de_US" instead of "en_US":

// => Returns "de_US"
NSString *regionCode = [[NSLocale currentLocale] objectForKey:NSLocaleIdentifier];
NSLog(@"Region code: %@", regionCode);

Below iOS 11, it returns "en_US".

My device has for language and region English / United States. Preferred languages (despite I do not use them in my code) are in order:

  1. English
  2. Deutsch
  3. French

Is it a known issue of iOS 11? Has the API changed?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
hico
  • 1,850
  • 1
  • 19
  • 28
  • Does this happen on a device or in the simulator? And furthermore: the app has an English localization? – mschmidt Dec 06 '17 at 15:12
  • It happens on a device: iPhone 6 Plus. App has only one localization: "Localizable.strings" file in Xcode target. Values are in German in this file, but I didn't specified it was German file in Xcode. So I'm wondering where this "de_" comes from. – hico Dec 06 '17 at 15:32

1 Answers1

16

Found it!

It's a change behaviour starting from iOS 11.

Under iOS 11, [NSLocale currentLocale] only returns languages supported by your app’s localizations. If your app only supports English (as the base localization), then no matter what language the user selects on the device, currentLocale will always return English.

Under iOS 10 and earlier, currentLocale would directly represent the user’s chosen language and region, regardless of what localizations your app supports.

More information here:

hico
  • 1,850
  • 1
  • 19
  • 28
  • If those localisations are the same then I guess your application is entirely about angst, kindergartens and schadenfreude? Jokes aside, Apple still documents `.current/-currentLocale` to be a function only of "the settings for the current user’s chosen system locale overlaid with any custom settings the user has specified" but notes that a locale represents "linguistic, cultural, and technological conventions", not merely a language. So are you using kilometres, the 24-hour clock, normal dd/mm/yyyy date display, etc? – Tommy Dec 06 '17 at 16:30
  • Please note that if both your German and English Localizable.strings files are exactly the same then you are going to have very upset users. The App Store will claim that your app supports both German and English. But since you didn't actually localize both strings files (you stated they were the same), then both German and English speaking users are going to see which ever language you actually have (I can't tell whether you have both files in German or English). – rmaddy Dec 06 '17 at 16:37
  • You are right, I didn't notice German AND English would be listed as supported on the store. Which is actually false as both of the translations are the same... Saw your stackoverflow link. So it's truly a change of iOS 11. iOS will detect that I only have German, and so it will always return German... Don't know what to do here. – hico Dec 07 '17 at 10:40
  • I am currently facing the same problem in one of my Today Widgets. My App is localized in many different languages but the widget keeps showing the EN text on my DE device. Any idea? – Georg Nov 09 '18 at 20:13
  • how about iOS 14? – Ahmadreza Oct 06 '20 at 06:57