Replace unmaintained lexical-sort with ICU
This commit is contained in:
parent
24cacb0da8
commit
3caea33288
6 changed files with 290 additions and 8 deletions
|
|
@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
|
|||
use std::collections::BTreeMap;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use crate::fl;
|
||||
use crate::{fl, localize::LANGUAGE_SORTER};
|
||||
|
||||
pub const CONFIG_VERSION: u64 = 1;
|
||||
pub const COSMIC_THEME_DARK: &str = "COSMIC Dark";
|
||||
|
|
@ -311,7 +311,7 @@ impl Config {
|
|||
|
||||
color_scheme_names.push((name, *color_scheme_id));
|
||||
}
|
||||
color_scheme_names.sort_by(|a, b| lexical_sort::natural_lexical_cmp(&a.0, &b.0));
|
||||
color_scheme_names.sort_by(|a, b| LANGUAGE_SORTER.compare(&a.0, &b.0));
|
||||
color_scheme_names
|
||||
}
|
||||
|
||||
|
|
@ -347,7 +347,7 @@ impl Config {
|
|||
|
||||
profile_names.push((name, *profile_id));
|
||||
}
|
||||
profile_names.sort_by(|a, b| lexical_sort::natural_lexical_cmp(&a.0, &b.0));
|
||||
profile_names.sort_by(|a, b| LANGUAGE_SORTER.compare(&a.0, &b.0));
|
||||
profile_names
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ pub fn key_binds() -> HashMap<KeyBind, Action> {
|
|||
bind!([Ctrl], Key::Character("-".into()), ZoomOut);
|
||||
bind!([Ctrl], Key::Character("=".into()), ZoomIn);
|
||||
bind!([Ctrl], Key::Character("+".into()), ZoomIn);
|
||||
|
||||
|
||||
// Ctrl+Arrows and Ctrl+HJKL move between splits
|
||||
bind!([Ctrl, Shift], Key::Named(Named::ArrowLeft), PaneFocusLeft);
|
||||
bind!([Ctrl, Shift], Key::Character("H".into()), PaneFocusLeft);
|
||||
|
|
|
|||
|
|
@ -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) => {{
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ use cosmic::{
|
|||
};
|
||||
use cosmic_files::dialog::{Dialog, DialogKind, DialogMessage, DialogResult};
|
||||
use cosmic_text::{fontdb::FaceInfo, Family, Stretch, Weight};
|
||||
use localize::LANGUAGE_SORTER;
|
||||
use std::{
|
||||
any::TypeId,
|
||||
cmp,
|
||||
|
|
@ -460,9 +461,9 @@ impl App {
|
|||
}
|
||||
}
|
||||
self.theme_names_dark
|
||||
.sort_by(|a, b| lexical_sort::natural_lexical_cmp(a, b));
|
||||
.sort_by(|a, b| LANGUAGE_SORTER.compare(a, b));
|
||||
self.theme_names_light
|
||||
.sort_by(|a, b| lexical_sort::natural_lexical_cmp(a, b));
|
||||
.sort_by(|a, b| LANGUAGE_SORTER.compare(a, b));
|
||||
}
|
||||
|
||||
fn update_config(&mut self) -> Command<Message> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue