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.
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.
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!) ! } }
You can use Locale. getDefault(). getLanguage(); to get the usual language code (e.g. "de", "en").
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With