"Español (México)" language setting uses "Spanish" strings instead of "Spanish (Latin America)" strings

StackOverflow https://stackoverflow.com/questions/23550623

Frage

Our iOS project has localized strings for both "Spanish" (es.lproj) and "Spanish (Latin America)" (es-419.lproj), as created from within Xcode.

However, on the iPhone (U.S., latest iOS 7), the only language options for Spanish are "Español" and "Español (México)", no "Latin America". And when you select "Español (México)", it uses the "Spanish" strings from our app, not the "Spanish (Latin America)" strings, as one would expect.

On further investigation, [[NSBundle mainBundle] preferredLocalizations] returns @[@"es"]. This is even though [[NSBundle mainBundle] localizations] returns an array containing both "es" and "es-419".

However, [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] returns an array containing "es-MX".

And then the following expression:

[NSBundle preferredLocalizationsFromArray:@[@"es-419", @"es"]
                           forPreferences:@[@"es-MX"]]

returns @[@"es"].

Why would Xcode give us "Spanish (Latin America)" localization, when it is not used when you actually select the only Latin American Spanish option on the phone?

War es hilfreich?

Lösung

This has changed in iOS 9 and 10, and should work correctly. If your localization is not present in your project, though, it will pick up the Base localization if it exists. There is only one Base available; if your user has selected "es-MX" as his phone language and you only have "es", it will chose string from the Base localization and NOT from the "es" base Spanish translation.

Andere Tipps

Xcode lists many more languages than are supported by iOS. The list of languages supported by iOS is a moving target, expanding with every iOS release. You pretty much have to pick the closest thing available to your real target language from the list available at the time.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top