fluent_locale/lib.rs
1//! fluent-locale is an API for operating on locales and language tags.
2//! It's part of Project Fluent, a localization framework designed to unleash
3//! the expressive power of the natural language.
4//!
5//! The primary use of fluent-locale is to parse/modify/serialize language tags
6//! and to perform language negotiation.
7//!
8//! fluent-locale operates on a subset of [BCP47](http://tools.ietf.org/html/bcp47).
9//! It can parse full BCP47 language tags, and will serialize them back,
10//! but currently only allows for operations on primary subtags and
11//! unicode extension keys.
12//!
13//! In result fluent-locale is not suited to replace full implementations of
14//! BCP47 like [rust-language-tags](https://github.com/pyfisch/rust-language-tags),
15//! but is arguably a better option for use cases involving operations on
16//! language tags and for language negotiation.
17
18pub mod accepted_languages;
19pub mod negotiate;
20
21pub use accepted_languages::parse as parse_accepted_languages;
22pub use negotiate::negotiate_languages;
23pub use negotiate::NegotiationStrategy;
24
25pub fn convert_vec_str_to_langids<'a, I, J>(
26 input: I,
27) -> Result<Vec<unic_langid::LanguageIdentifier>, unic_langid::LanguageIdentifierError>
28where
29 I: IntoIterator<Item = J>,
30 J: AsRef<str> + 'a,
31{
32 let mut result = vec![];
33 for elem in input.into_iter() {
34 result.push(elem.as_ref().parse()?);
35 }
36 Ok(result)
37}
38
39pub fn convert_vec_str_to_langids_lossy<'a, I, J>(input: I) -> Vec<unic_langid::LanguageIdentifier>
40where
41 I: IntoIterator<Item = J>,
42 J: AsRef<str> + 'a,
43{
44 input
45 .into_iter()
46 .filter_map(|t| t.as_ref().parse().ok())
47 .collect()
48}