Expand description
Language Identifier and Locale contains a set of subtags which represent different fields of the structure.
Languageis the only mandatory field, which when empty, takes the valueund.Scriptis an optional field representing the written script used by the locale.Regionis the region used by the locale.Variantsis a list of optionalVariantsubtags containing information about the variant adjustments used by the locale.
Subtags can be used in isolation, and all basic operations such as parsing, syntax normalization
and serialization are supported on each individual subtag, but most commonly
they are used to construct a LanguageIdentifier instance.
Variants is a special structure which contains a list of Variant subtags.
It is wrapped around to allow for sorting and deduplication of variants, which
is one of the required steps of language identifier and locale syntax normalization.
§Examples
use icu::locale::subtags::{Language, Region, Script, Variant};
let language: Language =
    "en".parse().expect("Failed to parse a language subtag.");
let script: Script =
    "arab".parse().expect("Failed to parse a script subtag.");
let region: Region =
    "cn".parse().expect("Failed to parse a region subtag.");
let variant: Variant =
    "MacOS".parse().expect("Failed to parse a variant subtag.");
assert_eq!(language.as_str(), "en");
assert_eq!(script.as_str(), "Arab");
assert_eq!(region.as_str(), "CN");
assert_eq!(variant.as_str(), "macos");Notice: The subtags are normalized on parsing. That means
that all operations work on a normalized version of the subtag
and serialization is very cheap.
Structs§
- Language
 - A language subtag (examples: 
"en","csb","zh","und", etc.) - Region
 - A region subtag (examples: 
"US","CN","AR"etc.) - Script
 - A script subtag (examples: 
"Latn","Arab", etc.) - Subtag
 - A generic subtag.
 - Variant
 - A variant subtag (examples: 
"macos","posix","1996"etc.) - Variants
 - A list of variants (examples: 
["macos", "posix"], etc.)