///|
fn tag_present(tag : @langtag.LanguageTag?) -> Bool {
match tag {
None => false
Some(_) => true
}
}
///|
fn main {
// 1. Product catalog: canonicalize mixed-case storefront tags.
let storefront = @langtag.canonicalize_text("EN-latn-us").unwrap()
if storefront != "en-US" {
abort("storefront canonicalization failed")
}
println("CATALOG: EN-latn-us -> " + storefront)
// 2. CMS locale picker: reject malformed tags with stable diagnostics.
let (bad, diags) = @langtag.parse_with_diagnostics("en-u")
if tag_present(bad) || diags.length() == 0 {
abort("cms diagnostic path failed")
}
println("CMS: " + diags[0].format())
// 3. API content negotiation: Accept-Language chooses a packaged translation.
let chosen = @langtag.negotiate("fr-CH, fr;q=0.9, en;q=0.8, *;q=0.1", [
"en-US", "fr-FR", "de",
]).unwrap()
if chosen != "fr-FR" {
abort("negotiation failed")
}
println("API: negotiated " + chosen)
println("MoonLangTag acceptance: 3 scenarios passed")
}