Accept-Language vs preferredLanguage

Hi all,

When changing the System->General->Language values,

the Accept-Language field for HTTP requests on iOS8 shows values such as

"es-xl for Spanish(Mexico)

"en-us" for English, US.


Getting the preferred language from [[NSLocale preferredLanguage] objectAtIndex:0] however shows

"es-MX" for Spanish(Mexico)

"en" for English, US,


Is there another API which returns exactly the value set by iOS for Accept-Language header for a given System language setting ?

Or is there a way to construct that header ? I did not find any api returning "es-xl" for language or even "xl" for region.

Thanks,

- Ruchir

Is there another API which returns exactly the value set by iOS for Accept-Language header for a given System language setting ?

The mechanism used by CFNetwork is hard to replicate because, AFAICT, it depends on private APIs whose functionality is not available via any public API. Specifically there's doesn't seem to be a way to find out the default region for a language, which is necessary if you want to to map "en" to "en_US".

What do you need this info for?

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks Eskimo. That at least confirms I'm not missing an api.

The reason is there is a mix of requests going from UIWebview with default CFNetwork derived header

and custom requests with an explicitly set header. Ideally the values would be the same.

Accept-Language vs preferredLanguage
 
 
Q