Localize date strings

Mostly closes: #103

Analogous to my other patches that localize date strings (e.g.
pop-os/cosmic-files#277).

The "password:" prompt is not localized in this patch because PAM should
yield translated strings on its own. This needs further investigation.
This commit is contained in:
Josh Megnauth 2024-08-27 08:39:16 -04:00 committed by Josh Megnauth
parent 17b554d0dd
commit 4050ea8bfe
No known key found for this signature in database
GPG key ID: 70813183462EFAD3
5 changed files with 31 additions and 10 deletions

View file

@ -1,6 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-only
use std::sync::OnceLock;
use std::{
str::FromStr,
sync::{LazyLock, OnceLock},
};
use i18n_embed::{
fluent::{fluent_language_loader, FluentLanguageLoader},
@ -13,6 +16,19 @@ use rust_embed::RustEmbed;
struct Localizations;
pub static LANGUAGE_LOADER: OnceLock<FluentLanguageLoader> = OnceLock::new();
pub static LANGUAGE_CHRONO: LazyLock<chrono::Locale> = LazyLock::new(|| {
std::env::var("LC_TIME")
.ok()
.or_else(|| 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 {