This package has been deprecated

Author message:

This package has been moved to langtag-utils

@wapps/langtag-utils

1.0.2 • Public • Published

langtag-utils

A collection of useful utilities for bcp47 and rfc4647

lookup(tags, ranges, defaultValue)

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

yarn add @wapps/langtag-utils
# npm install --save @wapps/langtag-utils

Usage

import { lookup, navigatorLanguages, parse } from '@wapps/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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Published

Version History

  • Version
    Downloads (Last 7 Days)
    • Published

Package Sidebar

Install

npm i @wapps/langtag-utils

Weekly Downloads

125

Version

1.0.2

License

MIT

Unpacked Size

174 kB

Total Files

18

Last publish

Collaborators

  • hupe1980