Language name from ISO 639-1 code in Javascript

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

    Another solution is to use iso-639-1 package.

    Installation:

    npm install iso-639-1
    

    Usage in Node.js:

    const ISO6391 = require('iso-639-1')
    console.log(ISO6391.getAllCodes())  // ['aa', 'ab', ...]
    console.log(ISO6391.getName('cv'))  // 'Chuvash'
    console.log(ISO6391.getNativeName('cv'))  // 'чӑваш чӗлхи'
    

    Usage in browsers:

    
    
    

提交回复
热议问题