#language #object #region #localization #data

language-objects

Work with language objects for localization

3 stable releases

1.0.2 Aug 5, 2022

#40 in #objects


Used in 2 crates

ISC license

9KB
185 lines

language-objects

Work with language tags and basic language associated data.

Usage

// Language and Region are interned reference structures

let lng = Language::parse("en-US").unwrap();
println!("{}", lng.direction());
println!("{}", lng.native_name());
println!("{}", lng.international_name());
println!("{}", lng.region().international_name());

// some regions are parsed as language
assert!(Language::parse("us").unwrap() == Language::parse("en").unwrap());

// omitting region in language tag will supply a default region
assert!(Language::parse("en-US").unwrap() == Language::parse("en").unwrap());

// invalid language
if Language::parse("foozxc").is_none() {
    // procedure
}

let region = Region::parse("us").unwrap();
println!("{}", region.international_name());

// invalid region
if Region::parse("foozxc").is_none() {
    // procedure
}

Dependencies

~0.6–1.4MB
~32K SLoC