Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSLocale of loaded language in application

In my interface I'm showing the display name of a locale with this:

[[NSLocale currentLocale] displayNameForKey: NSLocaleIdentifier value: identifier]

But this gives the display name using the locale of the system which is not always the same as the locale of the app. For example, if I set my system in French and my app doesn't have a French localisation, it will give a French display name in an English interface. Instead I'd like to have an English display name in an English interface so I don't mix the languages.

like image 502
Jef Avatar asked Jan 08 '12 19:01

Jef


People also ask

What is NSLocale?

An object representing information about linguistic, cultural, and technological conventions that bridges to Locale ; use NSLocale when you need reference semantics or other Foundation-specific behavior.

How do you force Nslocalizedstring to use a specific language?

struct CustomLanguage { func createBundlePath () -> Bundle { let selectedLanguage = //recover the language chosen by the user (in my case, from UserDefaults) let path = Bundle. main. path(forResource: selectedLanguage, ofType: "lproj") return Bundle(path: path!) ! } }

How do I find current device language?

You can use Locale. getDefault(). getLanguage(); to get the usual language code (e.g. "de", "en").

How many languages does iOS support?

There Are Two Main Languages That Power iOS: Objective-C and Swift. You can use other languages to code iOS apps, but they may require significant workarounds that require more effort than needed.


1 Answers

I'm not sure if this is what you want... But this is a great way to see what language/localization your app is running in:

[[NSBundle mainBundle] preferredLocalizations]

If you app supports both English and French languages, it will return an array of both in the preferred order. On testing, the one at 0 seems to be the xib that is loaded and running.

like image 50
snwbuni Avatar answered Oct 23 '22 03:10

snwbuni