Why does NSBundle only return the first localization present in a bundle that matches the user's language preferences instead of all matches?
Given the localization directories returned by -[NSBundle localizations]
(en, es, it, nl)
and the language preferences set by the user as returned by -[NSLocale preferredLanguages]
( en, es, nl, ja, fr, de, it, pt-PT, sv, nb, fi, zh-Hans, zh-Hant, ko )
I expect all four available localizations to be returned in the preferred language order by -[NSBundle preferredLocaliza开发者_开发技巧tionsFromArray:] (or -preferredLocalizations or -preferredLocalizationsFromArray:forPreferences:).
Instead, -preferredLocalizationsFromArray: returns only "en" as a viable source of localized resources.
Why?
The documentation for preferredLocalizationsFromArray:
says
Returns one or more localizations from the specified list that a bundle object would use to locate resources for the current user.
I guess it's one and not or more.
You should probably file a bug about it.
This behaviour is still the same in iOS 10. It looks like the returned array will contain more than one entry only if those entries are considered compatible.
For example, if your bundle supports "pt" and "pt-BR", and the user has selected 'pt-BR' as their preferred language, then [[NSBundle mainBundle] preferredLocalizations]
will return ("pt-BR","pt")
, because it's acceptable to fall back to "pt" content if "pt-BR" content is missing.
精彩评论