#language-tag #bcp47

oxilangtag

Simple and fast implementation of language tag normalization and validation

1 unstable release

0.1.2 Apr 16, 2021
0.1.1 Jul 10, 2020
0.1.0 May 1, 2020
Download history 176/week @ 2021-07-04 205/week @ 2021-07-11 165/week @ 2021-07-18 200/week @ 2021-07-25 144/week @ 2021-08-01 354/week @ 2021-08-08 480/week @ 2021-08-15 386/week @ 2021-08-22 179/week @ 2021-08-29 177/week @ 2021-09-05 215/week @ 2021-09-12 424/week @ 2021-09-19 313/week @ 2021-09-26 340/week @ 2021-10-03 192/week @ 2021-10-10 409/week @ 2021-10-17

849 downloads per month
Used in 31 crates (6 directly)

MIT license

32KB
674 lines

oxilangtag

actions status Latest Version Released API docs

OxiLangTag is a Rust library allowing to validate and normalize language tags following RFC 5646 (BCP 47).

It is a fork of the language-tags focusing on RDF use cases. You might find the language-tags crate more convenient.

It allows zero stack allocation language tag validation. Getters are also provided to easily retrieve the various language tag components.

Example:

use oxilangtag::LanguageTag;

// Parsing and validation
let language_tag = LanguageTag::parse("zh-cmn-Hans-CN-x-test").unwrap();
assert_eq!(language_tag.as_str(), "zh-cmn-Hans-CN-x-test");

// Language tag components
assert_eq!(language_tag.primary_language(), "zh");
assert_eq!(language_tag.extended_language(), Some("cmn"));
assert_eq!(language_tag.full_language(), "zh-cmn");
assert_eq!(language_tag.script(), Some("Hans"));
assert_eq!(language_tag.region(), Some("CN"));
assert_eq!(language_tag.extension(), None);
assert_eq!(language_tag.private_use_subtags().collect::<Vec<_>>(), vec!["test"]);

License

This project is licensed under the MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT).

It is based on the language-tags crate by pyfisch under MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Futures by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps

Ay`