Language name from ISO 639-1 code in Javascript

前端 未结 6 1928
傲寒
傲寒 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:46

    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"
    

提交回复
热议问题