Huperniketes
Huperniketes

Reputation: 970

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 preferredLocalizationsFromArray:] (or -preferredLocalizations or -preferredLocalizationsFromArray:forPreferences:).

Instead, -preferredLocalizationsFromArray: returns only "en" as a viable source of localized resources.

Why?

Upvotes: 3

Views: 1675

Answers (2)

Greg Ball
Greg Ball

Reputation: 3811

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.

Upvotes: 0

0xced
0xced

Reputation: 26478

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.

Upvotes: 2

Related Questions