{"id":10273,"date":"2014-12-09T15:23:16","date_gmt":"2014-12-09T20:23:16","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=10273"},"modified":"2014-12-09T15:23:16","modified_gmt":"2014-12-09T20:23:16","slug":"nslocale-preferredlanguages-vs-nsbundle-preferredlocalizations","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2014\/12\/09\/nslocale-preferredlanguages-vs-nsbundle-preferredlocalizations\/","title":{"rendered":"+[NSLocale preferredLanguages] vs -[NSBundle preferredLocalizations]"},"content":{"rendered":"<p><a href=\"https:\/\/gist.github.com\/mattt\/f00da093956f20945727#comment-1352701\">C&eacute;dric Luthi<\/a>:<\/p>\n<blockquote cite=\"https:\/\/gist.github.com\/mattt\/f00da093956f20945727#comment-1352701\"><p>Sometimes, you need to know which language your app is running in. Often, people will use <a href=\"http:\/\/nshipster.com\/nslocale\/#+preferredlanguages\" rel=\"noreferrer\">+[NSLocale preferredLanguages]<\/a>. Unfortunately this tells nothing about the language the app is actually displaying. It will just give you the ordered list as found in <em>Settings &#8594; General &#8594; Language &amp; Region &#8594; Preferred Language Order<\/em> on iOS or <em>System Preferences &#8594; Language &amp; Region &#8594; Preferred Languages<\/em> on OS X.<\/p><p>Imagine that the preferred language order is {English, French} but your app is German only. Calling <code>[[NSLocale preferredLanguages] firstObject]<\/code> will give you <em>English<\/em> when you want <em>German<\/em>.<\/p><p>The proper way to get the actual language used by the app is to use <a href=\"https:\/\/developer.apple.com\/library\/ios\/documentation\/Cocoa\/Reference\/Foundation\/Classes\/NSBundle_Class\/index.html#\/\/apple_ref\/occ\/instp\/NSBundle\/preferredLocalizations\" rel=\"noreferrer\">[[NSBundle mainBundle] preferredLocalizations]<\/a>.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>C&eacute;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 &#8594; General &#8594; Language &amp; Region &#8594; Preferred Language Order on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[69,31,309,30,71],"class_list":["post-10273","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-ios","tag-localization","tag-mac","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/10273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=10273"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/10273\/revisions"}],"predecessor-version":[{"id":10274,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/10273\/revisions\/10274"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=10273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=10273"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=10273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}