3

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?

Huperniketes
  • 940
  • 7
  • 17
  • Did you ever find the reason for this, or a solution? I'm looking at iOS 7 where this still seems to be the case... – epologee Oct 29 '13 at 09:31

2 Answers2

2

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.

0xced
  • 25,219
  • 10
  • 103
  • 255
  • I'm hoping we're both overlooking something obvious, or even not obvious, and it works like it says on the box. However, you just might have the correct answer and I'll need to code suitable replacements for NSBundle's localization and resource loading APIs. – Huperniketes Jun 11 '11 at 01:57
  • "However, clients who want all localizations in preference order can make repeated calls, each time taking the top localizations out of the list of localizations passed in." according to the latest NSBundle class reference. – Vincent Gable Jul 16 '15 at 02:14
0

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.

Greg Ball
  • 3,671
  • 3
  • 22
  • 15