Documentation | Crate informations | Repository |
This crate provides an implementation of language tags defined by RFC5646 (BCP47).
You can easily parse new language from anything that provides a [u8]
reference:
```rust
extern crate langtag;
use langtag::LanguageTag;
fn main() -> Result<(), langtag::Error> { let tag = LanguageTag::parse("fr-FR")?; assert_eq!(tag.language().unwrap().primary(), "fr"); assert!(tag == "Fr-fr"); // comparison is case-insensitive. Ok(()) } ```
Note that LanguageTag::parse
does not copy the data it is given,
but only borrows it.
You can create an owning LanguageTag
instance by using
LanguageTagBuf::parse_copy
instead.
Once parsed, you can exlore every component of the language tag using the provided functions.
When the language tags owns its buffer through Vec<u8>
,
it becomes possible to access the tag mutabily to modify it.
```rust
extern crate langtag;
use std::convert::TryInto;
use langtag::LangTag;
fn main() -> Result<(), langtag::Error> { let mut tag = LangTag::parsecopy("fr-FR")?; tag.languagemut().setprimary("jp".tryinto()?); tag.setregion(None); tag.extensionsmut().insert('f'.tryinto()?, "bar".tryinto()?); assert_eq!(tag, "jp-f-bar"); Ok(()) } ```
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.