Notably changes the signature of LocaleCategory::get_locales
from Option<String>
to Vec<String>
, as there could be multiple options and the first choice (what was returned before) might not be supported.
HCGVXOF7P3KKS2IMGVJWI2POVOZQFPXH26YVBJZRSOYSUM4CHUBQC
}
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()
pub fn match_locales(
available: &[LanguageIdentifier],
default: &LanguageIdentifier,
) -> Vec<LanguageIdentifier> {
// TODO: requesting locales should have platform-specific logic
let 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 now
supported.into_iter().cloned().collect()
}
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 {
None
locales.push(global_locale);
}
if let Ok(category_locale) = env::var(self.as_str()) {
locales.push(category_locale);