Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS8 Regional Localization (e.g. pt-BR)?

From what I understand, iOS8 now supports regional localisations (in this case I want to support pt-BR).

See http://www.ibabbleon.com/iOS-Language-Codes-ISO-639.html

I am having problems with this, testing this with a brand new single view application, in xcode I have added the pt and pt-BR languages to my project, and altered text accordingly in the pt.lproj and pt-BR.lproj directories.

After setting my device to pt-BR and running, the text displayed is always pt, not pt-BR as desired.

Indeed logging the preferred locale returned by NSLocale

NSString *language = [[NSLocale preferredLanguages] objectAtIndex:0];
NSLog(@"Locale = %@", language);

Returns only 'Locale = pt'...

Am I missing any steps or is this a bug in iOS8?

Thanks for any help...

like image 977
Chris Avatar asked Oct 16 '14 17:10

Chris


2 Answers

For some reason, iOS8 is using pt for Portuguese Brasil (instead of pt_BR). When you select Portuguese Portugal, the localization will be pt_PT

I've deleted the localization, and added the generic portuguese (and replaced with .strings files with the old ones).

like image 182
Lucas Avatar answered Nov 03 '22 21:11

Lucas


According to the apple docs a IETF BCP 47 should be returned. So you should get pt-BR if that's your preferred system language.

If what you want is only the current locale I suggest you use:

[[NSLocale currentLocale] localeIdentifier]

Replace currentLocale with autoupdatingCurrentLocale if you want to support locale changes while your app is running.

EDIT: Locale is not the same as language ID! Sorry for misunderstanding. Anyway "pt" is the correct language ID for Brazilian portuguese:

... For example, use pt as the language ID for Portuguese as it is used in Brazil and pt-PT as the language ID for Portuguese as it is used in Portugal. The Other submenu (at the bottom of the list) contains more languages and dialects.

From: https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/LocalizingYourApp/LocalizingYourApp.html

like image 28
Shank Avatar answered Nov 03 '22 22:11

Shank