15 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

#424 in Internationalization (i18n)

Download history 10/week @ 2024-07-21 51/week @ 2024-07-28 9/week @ 2024-08-04 15/week @ 2024-08-11 6/week @ 2024-08-18 29/week @ 2024-08-25 35/week @ 2024-09-01 20/week @ 2024-09-08 20/week @ 2024-09-15 100/week @ 2024-09-22 64/week @ 2024-09-29 20/week @ 2024-10-06 17/week @ 2024-10-13 16/week @ 2024-10-20 23/week @ 2024-10-27 21/week @ 2024-11-03

77 downloads per month
Used in 5 crates (3 directly)

MIT/Apache

650KB
12K SLoC

unic-locale Build Status Coverage Status

unic-locale is an API for managing Unicode Locale 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_locale::{Locale, ExtensionType};

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

assert_eq!(loc.language(), "en");
assert_eq!(loc.script(), None);
assert_eq!(loc.region(), Some("US"));

loc.extensions.unicode.set_keyword("ca", "buddhist")
    .expect("Setting extension failed.");

let val = loc.extensions.unicode.keyword("ca")
    .expect("Getting extension value failed.")
    .collect::<Vec<_>>();

assert_eq!(val, vec!["buddhist"]);

assert_eq!(&loc.to_string(), "en-US-u-ca-buddhist-hc-h12");

Macros

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

use unic_locale::locale;

let loc = locale!("en-US-u-hc-h24");

assert_eq!(&loc.to_string(), "en-US-u-hc-h24")

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

Status

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

In particular, the supported extensions list is very limited and the ergonomics of manipulating them should be improved.

Get Involved

unic-locale 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

~285–750KB
~18K SLoC