Skip to main content

validate_code

Function validate_code 

Source
pub fn validate_code(raw: &str) -> Result<String, String>
Expand description

Validate + normalize a BCP-47-ish locale code for the cms_locale registry. Content locales may be any well-formed tag — core provides metadata + graceful fallback via rustango::i18n::locale_info — but the tag must be structurally sane so it matches Accept-Language, keys translations predictably, and fits the 16-char column. Normalizes _→-, language→lowercase, script→Titlecase, region→UPPERCASE. Returns the normalized code, or a human-readable error message.

Mirrors rustango_cms::translation::validate_field_path. Pure; unit-tested.

§Errors

When the code is empty, over 16 chars, has an empty segment, or a segment isn’t a valid BCP-47 subtag.