#language-tag #bcp47

oxilangtag

Simple and fast implementation of language tag normalization and validation

2 releases

0.1.3 Mar 26, 2022
0.1.2 Apr 16, 2021
0.1.1 Jul 10, 2020
0.1.0 May 1, 2020

#36 in Internationalization (i18n)

Download history 681/week @ 2022-08-09 632/week @ 2022-08-16 635/week @ 2022-08-23 773/week @ 2022-08-30 777/week @ 2022-09-06 741/week @ 2022-09-13 842/week @ 2022-09-20 786/week @ 2022-09-27 841/week @ 2022-10-04 691/week @ 2022-10-11 692/week @ 2022-10-18 1069/week @ 2022-10-25 929/week @ 2022-11-01 632/week @ 2022-11-08 1534/week @ 2022-11-15 820/week @ 2022-11-22

4,287 downloads per month
Used in 46 crates (9 directly)

MIT license

32KB
681 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.

If serde is available, LanguageTag implements the Serialize and Deserialize traits and encodes the language tag as a string.

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 Oxilangtag by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~64KB