Replace unmaintained lexical-sort with ICU
This commit is contained in:
parent
24cacb0da8
commit
3caea33288
6 changed files with 290 additions and 8 deletions
|
|
@ -1,9 +1,13 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
use i18n_embed::{
|
||||
fluent::{fluent_language_loader, FluentLanguageLoader},
|
||||
DefaultLocalizer, LanguageLoader, Localizer,
|
||||
};
|
||||
use icu_collator::{Collator, CollatorOptions, Numeric};
|
||||
use icu_provider::DataLocale;
|
||||
use rust_embed::RustEmbed;
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
|
|
@ -22,6 +26,23 @@ lazy_static::lazy_static! {
|
|||
};
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref LANGUAGE_SORTER: Collator = {
|
||||
let mut options = CollatorOptions::new();
|
||||
options.numeric = Some(Numeric::On);
|
||||
|
||||
DataLocale::from_str(&LANGUAGE_LOADER.current_language().to_string())
|
||||
.or_else(|_| DataLocale::from_str(&LANGUAGE_LOADER.fallback_language().to_string()))
|
||||
.ok()
|
||||
.and_then(|locale| Collator::try_new(&locale, options).ok())
|
||||
.or_else(|| {
|
||||
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_rules! fl {
|
||||
($message_id:literal) => {{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue