How does iOS Show the List of Languages in the Translated String or in the Language's Locale.
I am attaching a screenshot of what I actually mean:
All I could find is this link
Update: I want to achieve something like this:
Where I can map the Country with its Language, which is actually in its Locale. So is there an LCID Kind of a thing where I can map it and get that Locale string using the LCID using an iOS API?
Mockup is Below
You can get a list of languages translated in the languages locale with the following code:
Objective-C:
NSArray *languages = [NSLocale preferredLanguages];
for (NSString *lang in languages)
{
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:lang];
NSString *translated = [locale displayNameForKey:NSLocaleIdentifier value:lang];
NSLog(@"%@, %@", lang, translated);
}
Swift:
let languages = NSLocale.preferredLanguages()
for lang in languages {
let locale = NSLocale(localeIdentifier: lang)
let translated = locale.displayNameForKey(NSLocaleIdentifier, value: lang)!
print("\(lang), \(translated)")
}
Output:
en, English fr, français de, Deutsch ja, 日本語 nl, Nederlands ...
I hope that this answers the first part of your question and perhaps helps with the second part.
Swift 3 update:
let languages = NSLocale.preferredLanguages
for lang in languages {
let locale = NSLocale(localeIdentifier: lang)
let translated = locale.displayName(forKey: NSLocale.Key.identifier, value: lang)!
print("\(lang), \(translated)")
}
LCIDs are a Windows concept. There is no such thing on iOS. Languages are generally identified by ISO 639-1 or 639-2 language codes.
From the way you frame your question, I think it would be best to start by reading Apple's internationalization and localization documentation. NSLocale is going to be your friend.
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