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

2019-02-17 11:15发布

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...

2条回答
我命由我不由天
2楼-- · 2019-02-17 11:23

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).

查看更多
Viruses.
3楼-- · 2019-02-17 11:34

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

查看更多
登录 后发表回答