-[NSBundle preferredLocalizationsFromArray:forPreferences:] doesn't fallback on country codes (or has inconsistent behavior)

Originator:kemenaran
Number:rdar://14228383 Date Originated:21-Jun-2013 03:04 PM
Status:Open Resolved:
Product:iOS SDK Product Version:7.0b1
Classification:Other Bug Reproducible:Always
 
Summary:

-[NSBundle preferredLocalizationsFromArray:forPreferences:] doesn't handle country codes properly.

A Country code in the `preferencesArray` argument work as expected; but when a country code is present in the `localizationsArray`, the method doesn't fallback on the generic language or on another country code of the same language.

Steps to reproduce:

// Some correct results
[NSBundle preferredLocalizationsFromArray:@[@"de", @"en"]    forPreferences:@[@"en"]];    // en    (expected)
[NSBundle preferredLocalizationsFromArray:@[@"de", @"en-GB"] forPreferences:@[@"en-GB"]]; // en-GB (expected)
[NSBundle preferredLocalizationsFromArray:@[@"de", @"en"]    forPreferences:@[@"en-GB"]]; // en    (expected)

// Some unexpected results
[NSBundle preferredLocalizationsFromArray:@[@"de", @"en-GB"] forPreferences:@[@"en"]];    // de    (unexpected)
[NSBundle preferredLocalizationsFromArray:@[@"de", @"fr-FR"] forPreferences:@[@"fr"]];    // de    (unexpected)
[NSBundle preferredLocalizationsFromArray:@[@"de", @"en-US"] forPreferences:@[@"en"]];    // en    (wtf)

Expected Results:

The method should fallback on another country code of the same language if available. Also the "en-US" locale should not be special-cased.

Notes:

This is also broken in iOS 6. I suspect it never worked as expected.

Comments

Sample Project

https://github.com/kemenaran/NSBundle-PreferredLocalizations-Sample


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!