Tuesday, December 9, 2014

+[NSLocale preferredLanguages] vs -[NSBundle preferredLocalizations]

Cédric Luthi:

Sometimes, you need to know which language your app is running in. Often, people will use +[NSLocale preferredLanguages]. Unfortunately this tells nothing about the language the app is actually displaying. It will just give you the ordered list as found in Settings → General → Language & Region → Preferred Language Order on iOS or System Preferences → Language & Region → Preferred Languages on OS X.

Imagine that the preferred language order is {English, French} but your app is German only. Calling [[NSLocale preferredLanguages] firstObject] will give you English when you want German.

The proper way to get the actual language used by the app is to use [[NSBundle mainBundle] preferredLocalizations].

1 Comment RSS · Twitter

[…] +[NSLocale preferredLanguages] vs -[NSBundle preferredLocalizations] […]

Leave a Comment