Merge pull request #116 from joshuamegnauth54/issue-103-localize-datetime-password-prompt
Localize date strings
This commit is contained in:
commit
cd9fc48c6f
5 changed files with 31 additions and 10 deletions
|
|
@ -912,14 +912,13 @@ impl cosmic::Application for App {
|
|||
let mut column = widget::column::with_capacity(2).padding(16.0).spacing(12.0);
|
||||
|
||||
let dt = chrono::Local::now();
|
||||
let locale = *crate::localize::LANGUAGE_CHRONO;
|
||||
|
||||
//TODO: localized format
|
||||
let date = dt.format("%A, %B %-d");
|
||||
let date = dt.format_localized("%A, %B %-d", locale);
|
||||
column = column
|
||||
.push(widget::text::title2(format!("{}", date)).style(style::Text::Accent));
|
||||
|
||||
//TODO: localized format
|
||||
let time = dt.format("%R");
|
||||
let time = dt.format_localized("%R", locale);
|
||||
column = column.push(
|
||||
widget::text(format!("{}", time))
|
||||
.size(112.0)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -564,14 +564,13 @@ impl cosmic::Application for App {
|
|||
let mut column = widget::column::with_capacity(2).padding(16.0);
|
||||
|
||||
let dt = chrono::Local::now();
|
||||
let locale = *crate::localize::LANGUAGE_CHRONO;
|
||||
|
||||
//TODO: localized format
|
||||
let date = dt.format("%A, %B %-d");
|
||||
let date = dt.format_localized("%A, %B %-d", locale);
|
||||
column = column
|
||||
.push(widget::text::title2(format!("{}", date)).style(style::Text::Accent));
|
||||
|
||||
//TODO: localized format
|
||||
let time = dt.format("%R");
|
||||
let time = dt.format_localized("%R", locale);
|
||||
column = column.push(
|
||||
widget::text(format!("{}", time))
|
||||
.size(112.0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue