Handle language sorter errors

This commit is contained in:
Josh Megnauth 2024-07-08 02:28:35 -04:00
parent 783256fe8b
commit d7114aaeb9
No known key found for this signature in database
GPG key ID: 70813183462EFAD3

View file

@ -28,15 +28,16 @@ pub static LANGUAGE_LOADER: Lazy<FluentLanguageLoader> = Lazy::new(|| {
pub static LANGUAGE_SORTER: Lazy<Collator> = Lazy::new(|| { pub static LANGUAGE_SORTER: Lazy<Collator> = Lazy::new(|| {
let mut options = CollatorOptions::new(); let mut options = CollatorOptions::new();
options.numeric = Some(Numeric::On); options.numeric = Some(Numeric::On);
let collator = {
let current = LANGUAGE_LOADER.current_language().to_string();
let locale = DataLocale::from_str(&current).unwrap(); DataLocale::from_str(&LANGUAGE_LOADER.current_language().to_string())
let collator = Collator::try_new(&locale, options).unwrap(); .or_else(|_| DataLocale::from_str(&LANGUAGE_LOADER.fallback_language().to_string()))
collator .ok()
}; .and_then(|locale| Collator::try_new(&locale, options).ok())
.or_else(|| {
collator let locale = DataLocale::from_str("en-US").expect("en-US is a valid BCP-47 tag");
Collator::try_new(&locale, options).ok()
})
.expect("Creating a collator from the system's current language, the fallback language, or American English should succeed")
}); });
#[macro_export] #[macro_export]