16 releases (8 breaking)

0.9.5 May 11, 2024
0.9.4 Dec 13, 2023
0.9.1 Oct 19, 2022
0.9.0 May 6, 2020
0.4.1 Jul 29, 2019

#23 in Internationalization (i18n)

Download history 35544/week @ 2024-07-04 40789/week @ 2024-07-11 39735/week @ 2024-07-18 39653/week @ 2024-07-25 44015/week @ 2024-08-01 46798/week @ 2024-08-08 48243/week @ 2024-08-15 52334/week @ 2024-08-22 47541/week @ 2024-08-29 49268/week @ 2024-09-05 47418/week @ 2024-09-12 41796/week @ 2024-09-19 45478/week @ 2024-09-26 48745/week @ 2024-10-03 45210/week @ 2024-10-10 47457/week @ 2024-10-17

194,136 downloads per month
Used in 335 crates (93 directly)

MIT/Apache

605KB
12K SLoC

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.language(), "en");
assert_eq!(loc.script(), None);
assert_eq!(loc.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 mostly complete on the well-formed level. The next batch of work will go into API maturity.

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

~280–760KB
~18K SLoC