Expand description

Parsing, manipulating, and serializing Unicode Language and Locale Identifiers.

This module is published as its own crate (icu_locid) and as part of the icu crate. See the latter for more details on the ICU4X project.

The module provides algorithms for parsing a string into a well-formed language or locale identifier as defined by UTS #35: Unicode LDML 3. Unicode Language and Locale Identifiers.

Locale is the most common structure to use for storing information about a language, script, region, variants and extensions. In almost all cases, this struct should be used as the base unit for all locale management operations.

LanguageIdentifier is a strict subset of Locale which can be useful in a narrow range of cases where Unicode Extensions are not relevant.

If in doubt, use Locale.

Examples

use icu::locid::subtags::{Language, Region};
use icu::locid::Locale;

let mut loc: Locale = "en-US".parse().expect("Parsing failed.");

let lang: Language = "en".parse().expect("Parsing failed.");
let region: Region = "US".parse().expect("Parsing failed.");

assert_eq!(loc.id.language, lang);
assert_eq!(loc.id.script, None);
assert_eq!(loc.id.region, Some(region));
assert_eq!(loc.id.variants.len(), 0);

let region: Region = "GB".parse().expect("Parsing failed.");
loc.id.region = Some(region);

assert_eq!(loc.to_string(), "en-GB");

Macros

use icu::locid::{
    langid, subtags_language as language, subtags_region as region,
};

let lid = langid!("EN_US");

assert_eq!(lid.language, language!("en"));
assert_eq!(lid.region, Some(region!("US")));

For more details, see Locale and LanguageIdentifier.

Modules

Unicode Extensions provide a mechanism to extend the LanguageIdentifier with additional bits of information - a combination of a LanguageIdentifier and Extensions is called Locale.
Language Identifier and Locale contains a set of subtags which represent different fields of the structure.
Documentation on zero-copy deserialization of locale types.

Macros

A macro allowing for compile-time construction of valid Subtag subtags.
A macro allowing for compile-time construction of valid Subtag subtags.
A macro allowing for compile-time construction of valid Key subtags.
A macro allowing for compile-time construction of valid Attribute subtags.
A macro allowing for compile-time construction of valid Key subtags.
A macro allowing for compile-time construction of valid Unicode Value subtag.
A macro allowing for compile-time construction of valid LanguageIdentifiers.
A macro allowing for compile-time construction of valid Locales.
A macro allowing for compile-time construction of valid Language subtags.
A macro allowing for compile-time construction of valid Region subtags.
A macro allowing for compile-time construction of valid Script subtags.
A macro allowing for compile-time construction of valid Variant subtags.

Structs

A core struct representing a Unicode Locale Identifier.

Enums

List of parser errors that can be generated while parsing LanguageIdentifier, Locale, subtags or extensions.
The result of a subtag iterator comparison operation.