https://github.com/hupe1980/langtag-utils
A collection of useful utilities for bcp47 and rfc4647
https://github.com/hupe1980/langtag-utils
bcp-47 bcp47 rfc4647
Last synced: 6 months ago
JSON representation
A collection of useful utilities for bcp47 and rfc4647
- Host: GitHub
- URL: https://github.com/hupe1980/langtag-utils
- Owner: hupe1980
- License: mit
- Created: 2018-08-11T08:59:44.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T21:38:41.000Z (almost 3 years ago)
- Last Synced: 2025-03-13T08:59:48.079Z (7 months ago)
- Topics: bcp-47, bcp47, rfc4647
- Language: TypeScript
- Size: 465 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# langtag-utils
[](https://github.com/hupe1980/langtag-utils/workflows/Build/badge.svg)> A collection of useful utilities for [bcp47](https://tools.ietf.org/html/bcp47) and [rfc4647](https://tools.ietf.org/html/rfc4647#section-3.4)
### `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
```bash
npm install --save langtag-utils
```## How to use
```js
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](LICENSE)