Use icu for date and time localization (#934)

* Use icu for date and time localization

* Handle military time config in dialog
This commit is contained in:
Jason Hansen 2025-04-14 08:59:32 -06:00 committed by GitHub
parent 3245f762a6
commit 5e21c7cf99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 511 additions and 80 deletions

View file

@ -3,7 +3,7 @@
use std::{any::TypeId, num::NonZeroU16, path::PathBuf};
use cosmic::{
cosmic_config::{self, cosmic_config_derive::CosmicConfigEntry, ConfigGet, CosmicConfigEntry},
cosmic_config::{self, cosmic_config_derive::CosmicConfigEntry, CosmicConfigEntry},
iced::Subscription,
theme, Application,
};
@ -205,7 +205,7 @@ pub struct TabConfig {
pub show_hidden: bool,
/// Icon zoom
pub icon_sizes: IconSizes,
#[serde(skip, default = "military_time_enabled")]
#[serde(skip)]
/// 24 hour clock; this is neither serialized nor deserialized because we use the user's global
/// preference rather than save it
pub military_time: bool,
@ -220,27 +220,12 @@ impl Default for TabConfig {
folders_first: true,
show_hidden: false,
icon_sizes: IconSizes::default(),
military_time: military_time_enabled(),
military_time: false,
single_click: false,
}
}
}
/// Return whether the user enabled military time via the Time applet.
fn military_time_enabled() -> bool {
// Borrowed from COSMIC Greeter
match cosmic_config::Config::new("com.system76.CosmicAppletTime", 1) {
Ok(config_handler) => config_handler.get("military_time").unwrap_or_default(),
Err(err) => {
log::error!(
"failed to create CosmicAppletTime config handler: {:?}",
err
);
false
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, CosmicConfigEntry, Deserialize, Serialize)]
#[serde(default)]
pub struct IconSizes {
@ -270,3 +255,11 @@ impl IconSizes {
percent!(self.grid, ICON_SIZE_GRID) as _
}
}
pub const TIME_CONFIG_ID: &str = "com.system76.CosmicAppletTime";
#[derive(Debug, Default, Clone, CosmicConfigEntry, PartialEq, Eq)]
#[version = 1]
pub struct TimeConfig {
pub military_time: bool,
}