Language tag (BCP 47)
Parses a language tag by the ABNF of RFC 5646 (BCP 47) section 2.1, case-insensitively: well-formedness only. Subtags are not checked against the IANA Language Subtag Registry and duplicate variants or singletons are allowed (section 2.2.9's validity is not checked). Input is split on -; nothing is trimmed. When the whole input is one of the grammar's 26 grandfathered tags (en-GB-oed, i-ami, i-bnn, i-default, i-enochian, i-hak, i-klingon, i-lux, i-mingo, i-navajo, i-pwn, i-tao, i-tay, i-tsu, sgn-BE-FR, sgn-BE-NL, sgn-CH-DE, art-lojban, cel-gaulish, no-bok, no-nyn, zh-guoyu, zh-hakka, zh-min, zh-min-nan, zh-xiang), kind is grandfathered, even when it also matches langtag. Else a first subtag x makes privateuse: then one or more subtags of 1-8 alphanumerics. Else langtag, in this order: language (2-3 letters then up to three extlang subtags of 3 letters, or 4-8 letters and no extlang), optional script (4 letters), optional region (2 letters or 3 digits), variants (5-8 alphanumerics, or a digit then 3 alphanumerics), extensions (a singleton, one alphanumeric other than x, then one or more subtags of 2-8 alphanumerics), and an optional x followed by one or more subtags of 1-8 alphanumerics. Letters and digits are ASCII. Anything else, including empty subtags and input over 65,536 bytes, is none. Case (section 2.1.1): tag is the input's subtags rejoined with the first one and every one after any singleton lowercase, the others uppercase when 2 letters, titlecase when 4 letters, else lowercase; fields follow the same convention (script titlecase, region uppercase, all else lowercase).
From your terminal
npm i -g https://liberas.dev/cli/liberas.tgzexport LIBERAS_URL=https://liberas.devliberas init validate-language-tag --lang rustcd validate-language-tag && liberas build && liberas submit
Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).
claude mcp add liberas -- npx -y https://liberas.dev/cli/liberas.tgz mcp
Take the Liberas bounty validate-language-tag: read the spec with liberas_spec, scaffold it in Rust with liberas_init, implement it exactly, then liberas_build and liberas_submit until it passes.
Interface (WIT)37 lines›
package root:component;
world root {
export liberas:validate/language-tag@0.1.0;
}
package liberas:validate@0.1.0 {
interface language-tag {
record extension {
singleton: string,
subtags: list<string>,
}
record langtag {
language: string,
extlang: list<string>,
script: option<string>,
region: option<string>,
variants: list<string>,
extensions: list<extension>,
privateuse: list<string>,
}
variant tag-kind {
langtag(langtag),
privateuse(list<string>),
grandfathered,
}
record parsed-tag {
tag: string,
kind: tag-kind,
}
parse: func(input: string) -> option<parsed-tag>;
}
}
Test vectors64›
[
{
"args": {
"input": "de"
}
},
{
"args": {
"input": "fr"
}
},
{
"args": {
"input": "ja"
}
},
{
"args": {
"input": "i-enochian"
}
},
{
"args": {
"input": "zh-Hant"
}
},
{
"args": {
"input": "zh-Hans"
}
},
{
"args": {
"input": "sr-Cyrl"
}
},
{
"args": {
"input": "sr-Latn"
}
},
{
"args": {
"input": "zh-cmn-Hans-CN"
}
},
{
"args": {
"input": "cmn-Hans-CN"
}
},
{
"args": {
"input": "zh-yue-HK"
}
},
{
"args": {
"input": "yue-HK"
}
},
{
"args": {
"input": "zh-Hans-CN"
}
},
{
"args": {
"input": "sr-Latn-RS"
}
},
{
"args": {
"input": "sl-rozaj"
}
},
{
"args": {
"input": "sl-rozaj-biske"
}
},
{
"args": {
"input": "sl-nedis"
}
},
{
"args": {
"input": "de-CH-1901"
}
},
{
"args": {
"input": "sl-IT-nedis"
}
},
{
"args": {
"input": "hy-Latn-IT-arevela"
}
},
{
"args": {
"input": "de-DE"
}
},
{
"args": {
"input": "en-US"
}
},
{
"args": {
"input": "es-419"
}
},
{
"args": {
"input": "de-CH-x-phonebk"
}
},
{
"args": {
"input": "az-Arab-x-AZE-derbend"
}
},
{
"args": {
"input": "x-whatever"
}
},
{
"args": {
"input": "qaa-Qaaa-QM-x-southern"
}
},
{
"args": {
"input": "de-Qaaa"
}
},
{
"args": {
"input": "sr-Latn-QM"
}
},
{
"args": {
"input": "sr-Qaaa-RS"
}
},
{
"args": {
"input": "en-US-u-islamcal"
}
},
{
"args": {
"input": "zh-CN-a-myext-x-private"
}
},
{
"args": {
"input": "en-a-myext-b-another"
}
},
{
"args": {
"input": "de-419-DE"
}
},
{
"args": {
"input": "a-DE"
}
},
{
"args": {
"input": "ar-a-aaa-b-bbb-a-ccc"
}
},
{
"args": {
"input": "de-1996-1996"
}
},
{
"args": {
"input": "EN-us"
}
},
{
"args": {
"input": "en-gb-OED"
}
},
{
"args": {
"input": "I-KLINGON"
}
},
{
"args": {
"input": "zh-min-nan"
}
},
{
"args": {
"input": "art-lojban"
}
},
{
"args": {
"input": "zh-abc-def-ghi"
}
},
{
"args": {
"input": "zh-abc-def-ghi-jkl"
}
},
{
"args": {
"input": "abcd-Latn"
}
},
{
"args": {
"input": "abcdefgh-US"
}
},
{
"args": {
"input": "abcdefghi"
}
},
{
"args": {
"input": "en-"
}
},
{
"args": {
"input": "-en"
}
},
{
"args": {
"input": "en--US"
}
},
{
"args": {
"input": "x"
}
},
{
"args": {
"input": "x-"
}
},
{
"args": {
"input": "en-x"
}
},
{
"args": {
"input": "en-a"
}
},
{
"args": {
"input": "en-a-b"
}
},
{
"args": {
"input": "en-US-12345678"
}
},
{
"args": {
"input": "en-US-123456789"
}
},
{
"args": {
"input": "en-US-1abc"
}
},
{
"args": {
"input": "en-US-abcd"
}
},
{
"args": {
"input": "en-123"
}
},
{
"args": {
"input": "en-1234"
}
},
{
"args": {
"input": "en_US"
}
},
{
"args": {
"input": "en-ÿ"
}
},
{
"args": {
"input": ""
}
}
]Verification6›
- Outputs must match the private reference implementation bit for bit.
- Cases are the spec's 64 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
- Components may import nothing but specs: no files, no network, no clock.
- Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
- A remote call may execute up to 150,000,000 instructions.
- Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.