4

How does iOS Show the List of Languages in the Translated String or in the Language's Locale.

  • Is there an LCID associated with it?
  • If so, where can I find it's Mapping?
  • How does it work?
  • Is there an API or any documentation you can point me towards?

I am attaching a screenshot of what I actually mean: enter image description here

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
    enter image description here

JWWalker
  • 22,385
  • 6
  • 55
  • 76
aliasgar
  • 359
  • 4
  • 20
  • @MartinR it did! Still doing some research on it! Once im convinced i'll accept your answer. Beacuse these languages are on the Web Server, and the localization comes from there as a web service, so I need to map these LCIDs on the server to the Locale IDs on iOS. Was hoping there is some universal convention like LCIDs. But as someone mentioned, its just a windows terminology! – aliasgar Dec 28 '12 at 07:18

2 Answers2

11

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)")
}
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
2

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.

Paul Lalonde
  • 5,020
  • 2
  • 32
  • 35