Need private packages and team management tools?Check out npm Teams »

langtag-utils

2.0.1 • Public • Published

langtag-utils

Build Status

A collection of useful utilities for bcp47 and rfc4647

lookup(tags, ranges, defaultValue = 'en')

Find the most appropriate language tag that matches a language priority list.

navigatorLanguages()

Retrieves the language information saved in window.navigator backwards compatible.

parse(tag)

Parses the language tag and returns an object with all available information.

Installation

npm install --save langtag-utils

How to use

import { lookup, navigatorLanguages, parse } from 'langtag-utils';
 
const whiteList = ['de', 'en'];
const fallbackLng = 'de';
const detectedLng = lookup(whiteList, navigatorLanguages(), fallbackLng);
 
...
 
console.log(parse('en-Latn-GB-boont-r-extended-sequence-x-private'));
/*
{
  langtag: {
    language: {
      language: 'en',
      extlang: [],
    },
    script: 'Latn',
    region: 'GB',
    variant: ['boont'],
    extension: [
      {
        singleton: 'r',
        extension: ['extended', 'sequence'],
      },
    ],
    privateuse: ['private'],
  },
  privateuse: [],
  grandfathered: {
    irregular: null,
    regular: null,
  }
}
*/
 
...
 

License

MIT

Install

npm i langtag-utils

DownloadsWeekly Downloads

226

Version

2.0.1

License

MIT

Unpacked Size

16.5 kB

Total Files

19

Last publish

Collaborators

  • avatar