Macro mas_i18n::locale

source ·
macro_rules! locale {
    ($locale:literal) => { ... };
}
Expand description

A macro allowing for compile-time construction of valid Locales.

The macro will perform syntax canonicalization of the tag.

§Examples

use icu::locid::{locale, Locale};

const DE_AT: Locale = locale!("de_at");

let de_at: Locale = "de_at".parse().unwrap();

assert_eq!(DE_AT, de_at);

Note: The macro cannot produce locales with more than one variant or multiple extensions (only single keyword unicode extension is supported) due to const limitations (see Heap Allocations in Constants):

icu::locid::locale!("sl-IT-rozaj-biske-1994");

Use runtime parsing instead:

"sl-IT-rozaj-biske-1994"
    .parse::<icu::locid::Locale>()
    .unwrap();

Locales with multiple keys are not supported

icu::locid::locale!("th-TH-u-ca-buddhist-nu-thai");

Use runtime parsing instead:

"th-TH-u-ca-buddhist-nu-thai"
    .parse::<icu::locid::Locale>()
    .unwrap();

Locales with attributes are not supported

icu::locid::locale!("en-US-u-foobar-ca-buddhist");

Use runtime parsing instead:

"en-US-u-foobar-ca-buddhist"
    .parse::<icu::locid::Locale>()
    .unwrap();

Locales with single key but multiple types are not supported

icu::locid::locale!("en-US-u-ca-islamic-umalqura");

Use runtime parsing instead:

"en-US-u-ca-islamic-umalqura"
    .parse::<icu::locid::Locale>()
    .unwrap();