langtag

Crates.iolangtag
lib.rslangtag
version0.4.0
sourcesrc
created_at2020-12-18 19:01:54.520922
updated_at2024-02-29 10:57:17.912169
descriptionLanguage tags implementation following RFC 5646
homepage
repositoryhttps://github.com/timothee-haudebourg/langtag
max_upload_size
id324414
size121,271
Timothée Haudebourg (timothee-haudebourg)

documentation

https://docs.rs/langtag

README

Language Tags

CI Crate informations License Documentation

This crate provides an implementation of language tags defined by RFC5646 (BCP47).

Usage

You can easily parse new language from any string:

use langtag::LangTag;

fn main() -> Result<(), langtag::InvalidLangTag<&'static str>> {
  let tag = LangTag::new("fr-FR")?;
  assert_eq!(tag.language().unwrap().primary(), "fr");
  assert!(tag == "Fr-fr"); // comparison is case-insensitive.
  Ok(())
}

Note that LangTag::new does not copy the data it is given, but only borrows it. The LangTagBuf type allows you to own the language tag. Once parsed, you can explore every component of the language tag using the provided functions.

License

Licensed under either of

at your option.

Contribution

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.

Commit count: 29

cargo fmt