Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C : how to get the list of possible values returned by [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode]?

I use :

NSString *language = [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode];

to determine the user language.

Where can I get the full list of the possible returned values (e.g. "fr"), and corresponding language (e.g. "french").

Thanks !

like image 933
Regis_AG Avatar asked Oct 30 '25 00:10

Regis_AG


1 Answers

There are 2 ways you can go.

  1. Iterate over Locale.isoLanguageCodes and extract all 2-letter codes:
    for languageCode in Locale.isoLanguageCodes {
        print(languageCode) // or print(languageCode.prefix(2))
    }
  1. Iterate over Locale.availableIdentifiers and execute Locale.components(fromIdentifier:_) on every item.
for identifier in Locale.availableIdentifiers {
    let components = Locale.components(fromIdentifier: identifier)
    // ...
 }

A full list is standardized in ISO-639-1 list.

like image 161
robinkunde Avatar answered Oct 31 '25 14:10

robinkunde