@phensley/language-tag
v1.9.2
Published
Parsing and construction of BCP 47 language tags
Downloads
17,314
Readme
@phensley/language-tag
Implements BCP 47 language tag parsing and construction.
Installation
NPM:
npm install --save @phensley/language-tag
Yarn:
yarn add @phensley/language-tag
Examples
const IDS = ['en', 'es', 'es-419', 'und-AR', 'und-Hant', 'iw', 'i-klingon'];
for (const id of IDS) {
const tag = parseLanguageTag(id);
console.log(`${tag.compact().padStart(10)} ${tag.expanded()}`);
}
en en-Zzzz-ZZ
es es-Zzzz-ZZ
es-419 es-Zzzz-419
und-AR und-Zzzz-AR
und-Hant und-Hant-ZZ
iw iw-Zzzz-ZZ
tlh tlh-Zzzz-ZZ
const t = new LanguageTag(undefined, 'latn', 'us', 'PoSiX', {
u: ['ca-gregory']
});
console.log(t.expanded());
und-Latn-US-posix-u-ca-gregory