improv(keyboard): localize input sources with dgettext

This commit is contained in:
Michael Aaron Murphy 2025-01-08 17:33:04 +01:00
parent a9d97b5f4d
commit 5b41a76da7
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
6 changed files with 24 additions and 5 deletions

1
Cargo.lock generated
View file

@ -1650,6 +1650,7 @@ dependencies = [
"fontdb 0.16.2",
"freedesktop-desktop-entry",
"futures",
"gettext-rs",
"hostname-validator",
"hostname1-zbus",
"i18n-embed",

View file

@ -72,6 +72,9 @@ fontdb = "0.16.2"
fixed_decimal = "0.5.6"
mime = "0.3.17"
rustix = "0.38.41"
gettext-rs = { version = "0.7.2", features = [
"gettext-system",
], optional = true }
[dependencies.cosmic-settings-subscriptions]
git = "https://github.com/pop-os/cosmic-settings-subscriptions"
@ -95,6 +98,7 @@ optional = true
[features]
default = ["a11y", "dbus-config", "linux", "single-instance", "wgpu"]
gettext = ["dep:gettext-rs"]
# Default features for Linux
linux = [
@ -120,6 +124,7 @@ page-bluetooth = ["dep:bluez-zbus", "dep:zbus"]
page-date = ["dep:timedate-zbus", "dep:zbus"]
page-default-apps = ["dep:mime-apps"]
page-input = [
"gettext",
"dep:cosmic-comp-config",
"dep:cosmic-settings-config",
"dep:udev",

View file

@ -149,6 +149,11 @@ pub fn main() -> color_eyre::Result<()> {
init_logger();
init_localizer();
#[cfg(feature = "gettext")]
{
let _ = gettextrs::setlocale(gettextrs::LocaleCategory::LcAll, "");
}
let args = Args::parse();
let settings = cosmic::app::Settings::default()

View file

@ -338,7 +338,7 @@ impl page::Page<crate::pages::Message> for Page {
self.keyboard_layouts.insert((
layout.name().to_owned(),
String::new(),
layout.description().to_owned(),
gettextrs::dgettext("xkeyboard-config", layout.description()),
source.clone(),
));
@ -347,7 +347,7 @@ impl page::Page<crate::pages::Message> for Page {
(
layout.name().to_owned(),
variant.name().to_owned(),
variant.description().to_owned(),
gettextrs::dgettext("xkeyboard-config", variant.description()),
source.clone(),
)
})
@ -395,6 +395,13 @@ impl page::Page<crate::pages::Message> for Page {
Task::none()
}
fn on_leave(&mut self) -> Task<crate::pages::Message> {
self.active_layouts = Vec::new();
self.keyboard_layouts = SlotMap::new();
self.input_source_search = String::new();
Task::none()
}
}
impl Page {

View file

@ -208,6 +208,7 @@ impl Model {
pub(super) fn on_clear(&mut self) {
self.shortcut_models.clear();
self.shortcut_models.shrink_to_fit();
}
/// Gets the custom configuration for keyboard shortcuts.

View file

@ -203,9 +203,9 @@ impl page::Page<crate::pages::Message> for Page {
}
fn on_leave(&mut self) -> Task<crate::pages::Message> {
self.search.actions.clear();
self.search.localized.clear();
self.search.input.clear();
self.search.actions = SlotMap::new();
self.search.localized = SecondaryMap::new();
self.search.input = String::new();
self.search_model.on_clear();
self.modified.custom = 0;
self.modified.manage_windows = 0;