BCP 47 语言标记
Intl 对象中构造函数中的 locales 参数必须是一个 BCP 47 语言标记的字符串,或者是一个包括多个语言标记的数组。下面就对 BCP 47 语言标记 作一下自己的理解。
内容格式预览
一个 BCP 47 语言标记代表了一种语言或者区域(两者没有很大的区别)。在其最常见的格式中,它以这样的顺序囊括了这些内容:语言代码,脚本代码,国家代码。全部由连字符分隔开。例如:
①
- "zh": 中文
- "zh-cmn": 中文普通话
- "zh-cmn-Hans": 中文普通话简体
②
- "zh": 中文
- "zh-Hans": 简体中文
- "zh-Hans-CN": 中华人民共和国大陆简体中文
格式解析
Language-Tag = langtag ; 普通的语言标记
/ privateuse ; 私有用途的标记
/ grandfathered ; 祖父级的标记(不太理解这儿)
langtag = language
["-" script] ; 0 或 1 个 script
["-" region] ; 0 或 1 个 region
*("-" variant) ; 0 或无数个 variant
*("-" extension) ; 0 或无数个 extension
["-" privateuse] ; 0 或 1 个 privateuse
language = 2*3ALPHA ; 最短的 ISO 639 编码
["-" extlang] ; 有时后面会紧跟扩展的语言子标记
; 扩展语言子标签
/ 4ALPHA ; 预留给未来使用
/ 5*8ALPHA ; 已注册的语言子标记
extlang = 3ALPHA ; ISO 639 标准中的编码
*2("-" 3ALPHA) ;
script = 4ALPHA ; ISO 15924 标准中列出的编码
region = 2ALPHA ; 2 个字母序列(ISO 3166-1 编码)
/ 3DIGIT ; UN M.49 code
variant = 5*8alphanum ; 由 5 到 8 个字母数字序列或 1 个数字及 3 个字母或数字序列表示,并且经过注册
/ (DIGIT 3alphanum)
extension = singleton 1*("-" (2*8alphanum))
; Single alphanumerics
; "x" reserved for private use
singleton = DIGIT ; 0 - 9
/ %x41-57 ; A - W
/ %x59-5A ; Y - Z
/ %x61-77 ; a - w
/ %x79-7A ; y - z
privateuse = "x" 1*("-" (1*8alphanum))
grandfathered = irregular ; 在 RFC 3066 期间已注册非冗余标签
/ regular ; 在 RFC 3066 期间已注册非冗余标签
irregular = "en-GB-oed" ; irregular tags do not match
/ "i-ami" ; the 'langtag' production and
/ "i-bnn" ; would not otherwise be
/ "i-default" ; considered 'well-formed'
/ "i-enochian" ; These tags are all valid,
/ "i-hak" ; but most are deprecated
/ "i-klingon" ; in favor of more modern
/ "i-lux" ; subtags or subtag
/ "i-mingo" ; combination
/ "i-navajo"
/ "i-pwn"
/ "i-tao"
/ "i-tay"
/ "i-tsu"
/ "sgn-BE-FR"
/ "sgn-BE-NL"
/ "sgn-CH-DE"
regular = "art-lojban" ; these tags match the 'langtag'
/ "cel-gaulish" ; production, but their subtags
/ "no-bok" ; are not extended language
/ "no-nyn" ; or variant subtags: their meaning
/ "zh-guoyu" ; is defined by their registration
/ "zh-hakka" ; and all of these are deprecated
/ "zh-min" ; in favor of a more modern
/ "zh-min-nan" ; subtag or sequence of subtags
/ "zh-xiang"
alphanum = (ALPHA / DIGIT) ; letters and numbers
复制代码
涉及到的代码
代码 | 含义 |
---|---|
ALPHA | 字母 |
alphanum | 字母或数字 |
查找 BCP 47 中的语言子标记含义
在 BCP 47 中表示语言,脚本,国家(区域)和变体(少用)的语言子标记含义可以在 IANA 语言子标记注册 中找到。
总结
我对 BCP 47 语言标记 的理解尚处在最浅层次,文章有误请指正。