Language name from ISO 639-1 code in Javascript

There are some similar questions on stackoverflow. I needed a javascript function for getting English names and Native names for different languages. I found a nice json formatted list of ISO 693-1 language codes on stackoverflow (based on wikipedia) and created a gist with two functions getLanguageName and getLanguageNativeName. Here is how to use it:

getLanguageNativeName("cv"); // --> "чӑваш чӗлхи"
getLanguageName("cv"); // --> "Chuvash"
getLanguageNativeName("cv-RU"); // --> "чӑваш чӗлхи"
getLanguageName("cv-RU"); // --> "Chuvash"

I used it to answer another similar question: generate a list of localized language names with links to google translate


I think you are stuck with having to maintain your own list of mappings to native language names for each of the languages you wish to support. But it looks like Wikipedia has just what you need.


There is a native support for this in the new(ish) Intl API:

let languageNames = new Intl.DisplayNames(['en'], {type: 'language'});
languageNames.of('fr');      // "French"
languageNames.of('de');      // "German"
languageNames.of('fr-CA');   // "Canadian French"

If you want a name of an arbitrary language in an arbitrary language (e.g, how to say "Korean language" in Japanese), you can use Unicode CLDR data.

To use it in JavaScript, you may use cldr NPM package like:

cldr.extractLanguageDisplayNames('it').en;
# => 'inglese'

But not sure if the package only supports Node.js or also supports browsers. If not, you may search for other libraries or write your own code to parse CLDR directly.