iso-639-1

repository·master·Indexed 42 days ago

https://github.com/meikidd/iso-639-1

A simple interface for working with ISO-639-1 language codes version 3.1.6. Provides methods to look up English names, native names, and codes, as well as validation and bulk retrieval of language objects.

Tokens
1.8K
Snippets
16
Records
16
Agent score
3%

What's inside iso-639-1

  1. Use iso-639-1 in Browsers

    master

    To use the library in a browser, include the build file via a <script> tag. The library will be available under the global variable ISO6391.

    <script type="text/javascript" src="./node_modules/iso-639-1/build/index.js"></script>
    
    <script>
      console.log(ISO6391.getName('en')); // 'English'
    </script>
  2. Lookup language code by name

    master

    Use getCode(name) to find a language code using either its English name or its native name. Use getAllCodes() to retrieve an array of all ISO-639-1 codes.

    console.log(ISO6391.getCode('Chinese')); // 'zh'
    console.log(ISO6391.getCode('中文')); // 'zh'
    
    console.log(ISO6391.getAllCodes()); // ['aa','ab',...,'zu']
  3. Lookup language names by code

    master

    Use getName(code) to retrieve the English name of a language, or getNativeName(code) to retrieve its native name. Use getAllNames() and getAllNativeNames() to get arrays of all available names.

    console.log(ISO6391.getName('zh')); // 'Chinese'
    console.log(ISO6391.getNativeName('zh')); // '中文'
    
    console.log(ISO6391.getAllNames()); // ['Afar','Abkhaz', ... ,'Zulu']
    console.log(ISO6391.getAllNativeNames()); // ['Afaraf','аҧсуа бызшәа', ... ,'isiZulu']
  4. Get language objects by codes

    master

    Use getLanguages(codes) to retrieve an array of language objects for a provided list of codes. Each object contains the code, name, and nativeName.

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

    master

    Retrieve an array of language objects for a given list of ISO-639-1 codes. If a code is valid, it returns an object containing { code, name, nativeName }. If a code is invalid, it returns an object with empty strings for name and nativeName.

    const ISO6391 = require('iso-639-1');
    
    const languages = ISO6391.getLanguages(['en', 'fr', 'invalid']);
    // Returns: 
    // [
    //   { code: 'en', name: 'English', nativeName: 'English' },
    //   { code: 'fr', name: 'French', nativeName: 'Français' },
    //   { code: 'invalid', name: '', nativeName: '' }
    // ]
  6. Get a language name with ISO6391.getName()

    master

    Returns the English name of the language associated with the provided ISO-639-1 code. Returns an empty string if the code is invalid.

    const ISO6391 = require('iso-639-1');
    
    const name = ISO6391.getName('en'); // 'English'
    const invalid = ISO6391.getName('xx'); // ''
  7. Validate an ISO-639-1 code with ISO6391.validate()

    master

    Checks if a given string is a valid ISO-639-1 code present in the dataset. Returns true if valid, otherwise false.

    const ISO6391 = require('iso-639-1');
    
    const isValid = ISO6391.validate('en'); // true
    const isInvalid = ISO6391.validate('xyz'); // false