+[NSHTTPURLResponse localizedStringForStatusCode:] does not return localized messages

Originator:defagos
Number:rdar://32731428 Date Originated:June 13 2017, 7:39 AM
Status:Open Resolved:
Product:iOS SDK Product Version:All
Classification:Bug Reproducible:Always
 
Area:
CFNetwork Framework

Summary:
Contrary to what its prototype and documentation state, +[NSHTTPURLResponse localizedStringForStatusCode:] only returns messages in English. All localized messages exist in the CFNetwork bundle, which suggests the implementation is incorrect.

Steps to Reproduce:
Call for example [NSHTTPURLResponse localizedStringForStatusCode:502] on a device whose language has been set to French.

Expected Results:
The returned value is "passerelle incorrecte".

Observed Results:
The returned value is "bad gateway".

Version:
Tested on iOS 9.3 and above, iOS 11 beta 1 included.

Notes:
All strings have been already properly localized and are available from the CFNetwork bundle, though. Currently, we can therefore fix the implementation by using the value in English returned by +localizedStringForStatusCode: as localization key to retrieve the properly localized variant:

+ (NSString *)workaround_localizedStringForStatusCode:(NSInteger)statusCode
{
    NSString *localizationKey = [NSHTTPURLResponse localizedStringForStatusCode:statusCode];
    NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.apple.CFNetwork"];
    return [bundle localizedStringForKey:localizationKey value:localizationKey table:nil];
}

Comments


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!