3.1 KiB
3.1 KiB
bcp-47-normalize
Normalize, canonicalize, and format BCP 47 tags.
Install
npm:
npm install bcp-47-normalize
Use
var normalize = require('bcp-47-normalize')
var tags = [
'de-de-1901',
'en-gb',
'en-us',
'en-bu',
'hy-arevmda',
'nld-nl',
'no-nyn',
'pt-br',
'pt-pt',
'zh-hans-cn'
]
tags.forEach(function(tag) {
console.log('%s -> %s', tag, normalize(tag))
})
Yields:
de-de-1901 -> de-1901
en-gb -> en-GB
en-us -> en
en-bu -> en-MM
hy-arevmda -> hyw
nld-nl -> nl
no-nyn -> nn
pt-br -> pt
pt-pt -> pt-PT
zh-hans-cn -> zh-CN
API
normalize(tag[, options])
Normalize the given BCP 47 tag according to Unicode CLDR suggestions.
options.forgiving
Passed to bcp-47
as options.forgiving
.
options.warning
Passed to bcp-47
as options.warning
.
One additional warning is given:
code | reason |
---|---|
7 | Deprecated region CURRENT , expected one of SUGGESTIONS |
This warning is only given if the region cannot be automatically fixed (when regions split into multiple regions).
Returns
string
— Normal, canonical, and pretty BCP 47 tag.
Related
bcp-47
— Parse and stringify BCP 47 language tagsbcp-47-match
— Match BCP 47 language tags with language ranges per RFC 4647iso-3166
— ISO 3166 codesiso-639-2
— ISO 639-2 codesiso-639-3
— ISO 639-3 codesiso-15924
— ISO 15924 codesun-m49
— UN M49 codes