Add language negotiation using `fluent-langneg`
Dependencies
- [2]
T6JEWQJ7Implement converting `PosixLocale` to `icu_locid::Locale` - [3]
LIH6JCXYImplement POSIX locale category lookup - [4]
YNEOCYMGCreate `locale-select` crate - [*]
UKFEFT6LCreate basic `Output` proc-macro - [*]
O77KA6C4Create `fluent_embed` crate
Change contents
- replacement in locale_select/src/unix.rs at line 3
use icu_locid::subtags::{self, Variants};use icu_locid::subtags::{self, Language, Variants}; - edit in locale_select/src/unix.rs at line 5
use crate::fetch::unix::LocaleCategory; - edit in locale_select/src/unix.rs at line 202
}pub fn get_locales(category: LocaleCategory) -> Vec<LanguageIdentifier> {category.get_locales().iter().map(|locale_str| PosixLocale::from_str(locale_str)).map(|posix_locale| posix_locale.icu_locale()).filter_map(|potential_locale| potential_locale.ok())// TODO: is it ok to strip this posix metadata from the locale?.map(|locale| locale.id).collect() - edit in locale_select/src/lib.rs at line 1
use fluent_langneg::NegotiationStrategy;use icu_locid::LanguageIdentifier; - edit in locale_select/src/lib.rs at line 6[4.5413]
pub fn match_locales(available: &[LanguageIdentifier],default: &LanguageIdentifier,) -> Vec<LanguageIdentifier> {// TODO: requesting locales should have platform-specific logiclet requested = unix::get_locales(fetch::unix::LocaleCategory::Messages);let supported = fluent_langneg::negotiate_languages(&requested,&available,Some(&default),NegotiationStrategy::Matching,);// TODO: this is wasteful but avoids dealing with lifetimes for nowsupported.into_iter().cloned().collect()} - replacement in locale_select/src/fetch/unix.rs at line 3
enum PosixLocaleCategory {pub enum LocaleCategory { - replacement in locale_select/src/fetch/unix.rs at line 18
impl PosixLocaleCategory {impl LocaleCategory { - edit in locale_select/src/fetch/unix.rs at line 35
} - edit in locale_select/src/fetch/unix.rs at line 36
impl PosixLocaleCategory { - replacement in locale_select/src/fetch/unix.rs at line 44
fn get_locale(&self) -> Option<String> {pub fn get_locales(&self) -> Vec<String> {let mut locales = Vec::with_capacity(3); - replacement in locale_select/src/fetch/unix.rs at line 48
Some(global_locale)} else if let Ok(category_locale) = env::var(self.as_str()) {Some(category_locale)} else if let Ok(lang) = env::var("LANG") {Some(lang)} else {Nonelocales.push(global_locale);}if let Ok(category_locale) = env::var(self.as_str()) {locales.push(category_locale); - edit in locale_select/src/fetch/unix.rs at line 54
if let Ok(lang) = env::var("LANG") {locales.push(lang);}locales - replacement in locale_select/src/fetch/mod.rs at line 1
mod unix;[3.1643]pub mod unix; - edit in locale_select/Cargo.toml at line 7
fluent-langneg = { version = "0.14.0", features = ["cldr"] } - edit in Cargo.lock at line 74[7.1637][7.1637]
name = "fluent-langneg"version = "0.14.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "0a56f2b85e609878e71a22e16b2a8c5b9de24c3d5a1c780536f3800a6a114b07"dependencies = ["icu_locid","icu_locid_transform",][[package]] - edit in Cargo.lock at line 216
"fluent-langneg",