9 releases

0.4.0 Feb 29, 2024
0.3.4 May 22, 2023
0.3.2 Aug 18, 2022
0.3.0 Jul 7, 2022
0.1.1 Dec 18, 2020

#24 in Internationalization (i18n)

Download history 2035/week @ 2024-07-09 2014/week @ 2024-07-16 2065/week @ 2024-07-23 2483/week @ 2024-07-30 2958/week @ 2024-08-06 3135/week @ 2024-08-13 2584/week @ 2024-08-20 2787/week @ 2024-08-27 2827/week @ 2024-09-03 3034/week @ 2024-09-10 2956/week @ 2024-09-17 2933/week @ 2024-09-24 2495/week @ 2024-10-01 3436/week @ 2024-10-08 2563/week @ 2024-10-15 2462/week @ 2024-10-22

11,366 downloads per month
Used in 94 crates (15 directly)

MIT/Apache

51KB
1.5K SLoC

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.

Dependencies

~2.5–3.5MB
~76K SLoC