fix: Panic on long numerical file names

Closes: #258

[lexical_sort](https://github.com/Aloso/lexical-sort) is currently
unmaintained. The author recommends switching to the `icu` crate which
is maintained by the Unicode Consortium.
This commit is contained in:
Josh Megnauth 2024-07-08 02:00:52 -04:00
parent 5ec14f86b3
commit 783256fe8b
No known key found for this signature in database
GPG key ID: 70813183462EFAD3
6 changed files with 622 additions and 28 deletions

View file

@ -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 once_cell::sync::Lazy;
use rust_embed::RustEmbed;
@ -21,6 +25,20 @@ pub static LANGUAGE_LOADER: Lazy<FluentLanguageLoader> = Lazy::new(|| {
loader
});
pub static LANGUAGE_SORTER: Lazy<Collator> = Lazy::new(|| {
let mut options = CollatorOptions::new();
options.numeric = Some(Numeric::On);
let collator = {
let current = LANGUAGE_LOADER.current_language().to_string();
let locale = DataLocale::from_str(&current).unwrap();
let collator = Collator::try_new(&locale, options).unwrap();
collator
};
collator
});
#[macro_export]
macro_rules! fl {
($message_id:literal) => {{