Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

iso-google-locales

OneZee23139MIT3.0.4TypeScript support: included

Native language names for all ISO-639-1 codes plus some common IETF BCP 47 language tags

bcp-47, iso, iso-639, iso-639-1, language, language code, locale, locale code

readme

ISO-639-1-plus

NPM Version Build Status Download Count

Simple interface for ISO-639-1 2-letter language codes and common IETF BCP 47 language tags.

Forked from iso-639-1 and extended with a some common language subtags for regional variations (eg. en-GB, pt-BR, zh-Hans). The intention is not to provide a definitive list, but a subset of commonly used language tags / locales.

Installation

npm install iso-google-locales

Usage

Node.js

const ISO6391 = require('iso-google-locales');
console.log(ISO6391.getName('en-GB')); // 'English (United Kingdom)'

ES Module

import ISO6391 from 'iso-google-locales';
console.log(ISO6391.getName('en-GB')); // 'English (United Kingdom)'

Browsers

HTML

<script type="text/javascript" src="./node_modules/iso-google-locales/build/index.js"></script>

Visit global variable ISO6391 in js

console.log(ISO6391.getName('en-GB')); // 'English (United Kingdom)'

Methods

getName(code)

  • @param code {string}
  • @return {string}

Lookup language English name by code

getAllNames()

  • @return {array}

Get array of all language English names

getNativeName(code)

  • @param code {string}
  • @return {string}

Lookup language native name by code

getAllNativeNames()

  • @return {array}

Get array of all language native names

getCode(name)

  • @param name {string}
  • @return {string}

Lookup code by English name or native name

getAllCodes()

  • @return {array}

Get array of all codes

validate(code)

  • @param code {string}
  • @return {boolean}

Check whether the given code is in the list of ISO-639-1

getLanguages(codes)

  • @param codes {array}
  • @return {array}

Get the array of the language objects by the given codes

Example

const ISO6391 = require('iso-google-locales')

console.log(ISO6391.getName('zh')) // 'Chinese'
console.log(ISO6391.getNativeName('zh')) // '中文'

console.log(ISO6391.getAllNames()) // ['Afar','Abkhaz', ... ,'Zulu']
console.log(ISO6391.getAllNativeNames()) //['Afaraf','аҧсуа бызшәа', ... ,'isiZulu' ]

console.log(ISO6391.getCode('Chinese')) // 'zh'
console.log(ISO6391.getCode('中文')) // 'zh'

console.log(ISO6391.getAllCodes()) //['aa','ab',...,'zu']

console.log(ISO6391.validate('en')) // true
console.log(ISO6391.validate('xx')) // false

console.log(ISO6391.getLanguages(['en', 'zh']))
// [{code:'en',name:'English',nativeName:'English'},{code:'zh',name:'Chinese',nativeName:'中文'}]

changelog

iso-639-1-plus Changelog

v3.0 - Forked from iso-639-1

  • Add additional language variations not represented in iso-639-1, eg. en-GB, es-MX, pt-BR, zh-Hans
  • Lowercased a few language names as appropriate in the native language.

v2.1.9

  • Change hu native name "Magyar" -> "magyar" #40

    v2.1.8

  • Change hr native name "hrvatski jezik" -> "Hrvatski"
  • Change sl English name "Slovene" -> "Slovenian"

    v2.1.0

  • Correctly handle prototype property names passed as codes #20