| 1 |
oxilangtag |
| 2 |
========== |
| 3 |
|
| 4 |
[](https://github.com/oxigraph/oxilangtag/actions) |
| 5 |
[](https://crates.io/crates/oxilangtag) |
| 6 |
[](https://docs.rs/oxilangtag) |
| 7 |
|
| 8 |
OxiLangTag is a Rust library allowing to validate and normalize language tags following [RFC 5646](https://tools.ietf.org/html/rfc5646) |
| 9 |
([BCP 47](https://tools.ietf.org/html/bcp47)). |
| 10 |
|
| 11 |
It is a fork of the [`language-tags`](https://github.com/pyfisch/rust-language-tags/) focusing on [RDF use cases](https://www.w3.org/TR/rdf11-primer/). |
| 12 |
You might find the [`language-tags`](https://github.com/pyfisch/rust-language-tags/) crate more convenient. |
| 13 |
|
| 14 |
It allows zero stack allocation language tag validation. |
| 15 |
Getters are also provided to easily retrieve the various language tag components. |
| 16 |
|
| 17 |
If [`serde`](https://serde.rs/) is available, `LanguageTag` implements the `Serialize` and `Deserialize` traits and encodes the language tag as a string. |
| 18 |
|
| 19 |
Example: |
| 20 |
```rust |
| 21 |
use oxilangtag::LanguageTag; |
| 22 |
|
| 23 |
// Parsing and validation |
| 24 |
let language_tag = LanguageTag::parse("zh-cmn-Hans-CN-x-test").unwrap(); |
| 25 |
assert_eq!(language_tag.as_str(), "zh-cmn-Hans-CN-x-test"); |
| 26 |
|
| 27 |
// Language tag components |
| 28 |
assert_eq!(language_tag.primary_language(), "zh"); |
| 29 |
assert_eq!(language_tag.extended_language(), Some("cmn")); |
| 30 |
assert_eq!(language_tag.full_language(), "zh-cmn"); |
| 31 |
assert_eq!(language_tag.script(), Some("Hans")); |
| 32 |
assert_eq!(language_tag.region(), Some("CN")); |
| 33 |
assert_eq!(language_tag.extension(), None); |
| 34 |
assert_eq!(language_tag.private_use_subtags().collect::<Vec<_>>(), vec!["test"]); |
| 35 |
``` |
| 36 |
|
| 37 |
## License |
| 38 |
|
| 39 |
This project is licensed under the MIT license ([LICENSE-MIT](LICENSE-MIT) or `<http://opensource.org/licenses/MIT>`). |
| 40 |
|
| 41 |
It is based on the [`language-tags`](https://github.com/pyfisch/rust-language-tags/) crate by [pyfisch](https://github.com/pyfisch) under MIT license. |
| 42 |
|
| 43 |
|
| 44 |
### Contribution |
| 45 |
|
| 46 |
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. |