Language name from ISO 639-1 code in Javascript

前端 未结 6 1927
傲寒
傲寒 2020-12-19 00:04

I\'m building a website where people can associate a language information to content.

The website uses Javascript heavily and the language information associated to

6条回答
  •  半阙折子戏
    2020-12-19 00:51

    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

提交回复
热议问题