Localized date strings

Fixes some of #256

This patch also cleans up the `icu` dependencies from my last PR. I
added all of `icu` as a dependency last time because I assumed it would
be needed for this fix. However, `chrono` supports localization and
`icu` seemed harder to use anyway.
This commit is contained in:
Josh Megnauth 2024-07-12 02:20:41 -04:00
parent eba72e131a
commit 748d53fdbe
No known key found for this signature in database
GPG key ID: 70813183462EFAD3
4 changed files with 27 additions and 313 deletions

View file

@ -6,7 +6,7 @@ use i18n_embed::{
fluent::{fluent_language_loader, FluentLanguageLoader},
DefaultLocalizer, LanguageLoader, Localizer,
};
use icu::collator::{Collator, CollatorOptions, Numeric};
use icu_collator::{Collator, CollatorOptions, Numeric};
use icu_provider::DataLocale;
use once_cell::sync::Lazy;
use rust_embed::RustEmbed;
@ -40,6 +40,19 @@ pub static LANGUAGE_SORTER: Lazy<Collator> = Lazy::new(|| {
.expect("Creating a collator from the system's current language, the fallback language, or American English should succeed")
});
pub static LANGUAGE_CHRONO: Lazy<chrono::Locale> = Lazy::new(|| {
std::env::var("LANG")
.ok()
.and_then(|locale_full| {
// Split LANG because it may be set to a locale such as en_US.UTF8
locale_full
.split('.')
.next()
.and_then(|locale| chrono::Locale::from_str(locale).ok())
})
.unwrap_or(chrono::Locale::en_US)
});
#[macro_export]
macro_rules! fl {
($message_id:literal) => {{