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:
parent
17b554d0dd
commit
4050ea8bfe
5 changed files with 31 additions and 10 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue