Expand description
Deterministic BCP 47 locale-ID casting and vendor code mapping.
cbcp is the syntax layer below correspondence libraries: it casts locale
identifiers between their spellings without interpreting them. No tables of
meaning live here — no locale resolution, no country keywords, no variant
mapping, no greetings. Those belong to cletter and friends, which compose
this crate.
Two spellings, one rule:
- Storage/wire form is lowercase (
de-ch): filesystem paths, R2 keys, bundle variant IDs, URLs, PDF metadata. Produced bynormalize_locale_id. - Display form is BCP 47 (
de-CH): UI labels and vendor adapters that demand their own casing. Produced byto_bcp47.
Vendor adapters (deepl_source, deepl_target, google_language)
transliterate canonical codes into vendor-expected codes. They track vendor
documentation; a vendor change is a new cbcp minor version.
tests/vectors/*.json is the executable contract every port (Rust,
TypeScript, Python, Typst) implements verbatim.
Functions§
- base_
language - Extract the base ISO 639 language from a locale ID, lowercased.
DE-CH→de,en→en. Never fails; may return garbage for garbage. - deepl_
source DeepLsource language code: uppercaseISO 639base.de-CH→DE.- deepl_
target DeepLtarget language code. Regional defaults (EN-GB,PT-PT,ZH-HANS) are explicit product-wide contracts: every tool renders the same default for a bare language. Anything unmapped falls back to the uppercase base.- google_
language Googlelanguage code (Maps/Places/Translate): lowercaseISO 639base.de-CH→de.- is_
well_ formed - Structural well-formedness only:
llorlllalpha, then-xx…segments of 2–8 alphanumerics. No registry involved —xx-yypasses,en__USand""do not. - locale_
eq - Case- and separator-insensitive locale equality via normalization.
locale_eq("DE_CH", "de-ch")is true. - normalize_
locale_ id - Normalize an explicit locale ID’s spelling without inference or fallback.
- to_
bcp47 - Project a locale ID into BCP 47 display casing.