Skip to main content

Module language

Module language 

Source
Expand description

The language string format: an IETF BCP 47 language tag.

BCP 47 in full is a registry lookup, and this is deliberately not that. It checks the grammar — a primary subtag, then subtags of one to eight alphanumerics — and one semantic rule that a grammar check misses: RFC 5646 §2.2.9 forbids a variant or extension singleton subtag from appearing twice, so de-DE-1901-1901 and en-a-foo-a-bar are well formed and not valid tags. Upstream keeps those in language_parse_invalid.txt for the same reason it separates datetime’s calendar cases.

The primary subtag is required to be two or three lowercase letters, which is narrower than the RFC’s ABNF: that also admits a four-letter reserved range and five-to-eight-letter registered languages. The interop vectors declare jaja invalid and JA invalid, and following the vectors here costs nothing — no language in current use has a primary subtag outside ISO 639-1 and 639-3.

The two irregular openings are kept: x- starts a wholly private-use tag and i- starts a grandfathered one, and both bypass the primary-subtag rule because neither has one.

Enums§

LanguageError
Why a string is not a valid language tag.

Constants§

MAX_SUBTAG_LENGTH
Longest any one subtag may be.

Functions§

validate
Checks a string against the language tag rules.