| 1 | //! fluent-langneg 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-langneg is to parse/modify/serialize language tags |
| 6 | //! and to perform language negotiation. |
| 7 | //! |
| 8 | //! fluent-langneg 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-langneg 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 | |
| 18 | pub mod accepted_languages; |
| 19 | pub mod negotiate; |
| 20 | |
| 21 | pub use accepted_languages::parse as parse_accepted_languages; |
| 22 | pub use negotiate::negotiate_languages; |
| 23 | pub use negotiate::NegotiationStrategy; |
| 24 | |
| 25 | use unic_langid::{LanguageIdentifier, LanguageIdentifierError}; |
| 26 | |
| 27 | pub fn convert_vec_str_to_langids<'a, I, J>( |
| 28 | input: I, |
| 29 | ) -> Result<Vec<LanguageIdentifier>, LanguageIdentifierError> |
| 30 | where |
| 31 | I: IntoIterator<Item = J>, |
| 32 | J: AsRef<[u8]> + 'a, |
| 33 | { |
| 34 | inputimpl Iterator- >
|
| 35 | .into_iter() |
| 36 | .map(|s: J| LanguageIdentifier::from_bytes(s.as_ref())) |
| 37 | .collect() |
| 38 | } |
| 39 | |
| 40 | pub fn convert_vec_str_to_langids_lossy<'a, I, J>(input: I) -> Vec<LanguageIdentifier> |
| 41 | where |
| 42 | I: IntoIterator<Item = J>, |
| 43 | J: AsRef<[u8]> + 'a, |
| 44 | { |
| 45 | inputimpl Iterator |
| 46 | .into_iter() |
| 47 | .filter_map(|t: J| LanguageIdentifier::from_bytes(t.as_ref()).ok()) |
| 48 | .collect() |
| 49 | } |
| 50 | |