Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 275
user102008 Avatar asked Nov 23 '22 21:11

user102008


1 Answers

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.

like image 96
Corbin Miller Avatar answered May 07 '23 15:05

Corbin Miller