7 releases (4 breaking)

✓ Uses Rust 2018 edition

0.5.0 Sep 4, 2019
0.4.2 Aug 2, 2019
0.4.1 Jul 29, 2019
0.3.0 Jul 24, 2019
0.1.0 Jun 16, 2019

#28 in Internationalization (i18n)

Download history 22/week @ 2019-06-12 9/week @ 2019-06-19 13/week @ 2019-06-26 17/week @ 2019-07-03 19/week @ 2019-07-10 3/week @ 2019-07-17 94/week @ 2019-07-24 354/week @ 2019-07-31 366/week @ 2019-08-07 291/week @ 2019-08-14 308/week @ 2019-08-21 349/week @ 2019-08-28

631 downloads per month
Used in 9 crates (8 directly)

MIT/Apache

18KB
395 lines

unic-langid Build Status Coverage Status

unic-langid is an API for managing Unicode Language Identifiers.

The crate provides a way to create a struct from a string, manipulate its fields, canonicalize it, and serialize into a string.

Usage

use unic_langid::LanguageIdentifier;

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

assert_eq!(loc.get_language(), "en");
assert_eq!(loc.get_script(), None);
assert_eq!(loc.get_region(), Some("US"));

loc.set_script(Some("latn"));

assert_eq!(&loc.to_string(), "en-Latn-US");
use unic_langid::LanguageIdentifier;

let langid = LanguageIdentifier::from_parts(
    Some("en"),
    None,
    None,
    Some(&["nedis", "macos"])
).expect("Parsing failed.");

assert_eq!(&langid.to_string(), "en-macos-nedis")

Macros

unic-langid can be also compiled with features = ["macros"] which enables langid! macro:

use unic_langid::langid;

// The `const` assignment will currently work only
// if the langid doesn't contain any variants.
const EN_US: LanguageIdentifier = langid!("en-US");

fn main() {
    let de_at = langid!("de-AT");

    assert_eq!(&de_at.to_string(), "de-AT")
    assert_eq!(&EN_US.to_string(), "en-US")
}

The macro allows for compile-time parsing and validation of literal language identifiers.

Status

The crate is providing fundamental blocks, but is very basic.

In particular, a lot can be done to improve performance and memory usage.

Get Involved

unic-langid is open-source, licensed under the Apache License, Version 2.0. We encourage everyone to take a look at our code and we'll listen to your feedback.

Dependencies

~160KB