From 7d1c3bdcd55426e2d6edd35e81147a7e896fa86e Mon Sep 17 00:00:00 2001 From: Eduardo Flores Date: Sat, 9 Nov 2024 20:54:51 +0100 Subject: [PATCH] improv: support localization --- examples/about/src/main.rs | 2 +- src/widget/about.rs | 44 ++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/examples/about/src/main.rs b/examples/about/src/main.rs index 14a27805..6bc4a4ff 100644 --- a/examples/about/src/main.rs +++ b/examples/about/src/main.rs @@ -72,7 +72,7 @@ impl cosmic::Application for App { .developers([("Michael Murphy", "mmstick@system76.com")]) .links([ ("Website", "https://system76.com/cosmic"), - ("Repository", "https://github.com/pop-os/libcosmic)"), + ("Repository", "https://github.com/pop-os/libcosmic"), ("Support", "https://github.com/pop-os/libcosmic/issues"), ]); diff --git a/src/widget/about.rs b/src/widget/about.rs index 23a59189..1a9abcd3 100644 --- a/src/widget/about.rs +++ b/src/widget/about.rs @@ -1,5 +1,3 @@ -use iced_widget::tooltip::Position; -use license::License; #[cfg(feature = "desktop")] use { crate::{ @@ -7,7 +5,7 @@ use { widget::{self, horizontal_space}, Element, }, - std::collections::BTreeMap, + license::License, }; #[derive(Debug, Default, Clone, derive_setters::Setters)] @@ -30,28 +28,28 @@ pub struct About { license: Option, /// Artists who contributed to the application. #[setters(skip)] - artists: BTreeMap, + artists: Vec<(String, String)>, /// Designers who contributed to the application. #[setters(skip)] - designers: BTreeMap, + designers: Vec<(String, String)>, /// Developers who contributed to the application. #[setters(skip)] - developers: BTreeMap, + developers: Vec<(String, String)>, /// Documenters who contributed to the application. #[setters(skip)] - documenters: BTreeMap, + documenters: Vec<(String, String)>, /// Translators who contributed to the application. #[setters(skip)] - translators: BTreeMap, + translators: Vec<(String, String)>, /// Links associated with the application. #[setters(skip)] - links: BTreeMap, + links: Vec<(String, String)>, } impl<'a> About { /// Artists who contributed to the application. - pub fn artists(mut self, artists: impl Into>) -> Self { - let artists: BTreeMap<&'a str, &'a str> = artists.into(); + pub fn artists(mut self, artists: impl Into>) -> Self { + let artists: Vec<(&'a str, &'a str)> = artists.into(); self.artists = artists .into_iter() .map(|(k, v)| (k.to_string(), format!("mailto:{v}"))) @@ -60,8 +58,8 @@ impl<'a> About { } /// Designers who contributed to the application. - pub fn designers(mut self, designers: impl Into>) -> Self { - let designers: BTreeMap<&'a str, &'a str> = designers.into(); + pub fn designers(mut self, designers: impl Into>) -> Self { + let designers: Vec<(&'a str, &'a str)> = designers.into(); self.designers = designers .into_iter() .map(|(k, v)| (k.to_string(), format!("mailto:{v}"))) @@ -70,8 +68,8 @@ impl<'a> About { } /// Developers who contributed to the application. - pub fn developers(mut self, developers: impl Into>) -> Self { - let developers: BTreeMap<&'a str, &'a str> = developers.into(); + pub fn developers(mut self, developers: impl Into>) -> Self { + let developers: Vec<(&'a str, &'a str)> = developers.into(); self.developers = developers .into_iter() .map(|(k, v)| (k.to_string(), format!("mailto:{v}"))) @@ -80,8 +78,8 @@ impl<'a> About { } /// Documenters who contributed to the application. - pub fn documenters(mut self, documenters: impl Into>) -> Self { - let documenters: BTreeMap<&'a str, &'a str> = documenters.into(); + pub fn documenters(mut self, documenters: impl Into>) -> Self { + let documenters: Vec<(&'a str, &'a str)> = documenters.into(); self.documenters = documenters .into_iter() .map(|(k, v)| (k.to_string(), format!("mailto:{v}"))) @@ -90,8 +88,8 @@ impl<'a> About { } /// Translators who contributed to the application. - pub fn translators(mut self, translators: impl Into>) -> Self { - let translators: BTreeMap<&'a str, &'a str> = translators.into(); + pub fn translators(mut self, translators: impl Into>) -> Self { + let translators: Vec<(&'a str, &'a str)> = translators.into(); self.translators = translators .into_iter() .map(|(k, v)| (k.to_string(), format!("mailto:{v}"))) @@ -100,11 +98,11 @@ impl<'a> About { } /// Links associated with the application. - pub fn links(mut self, links: impl Into>) -> Self { - let links: BTreeMap<&'a str, &'a str> = links.into(); + pub fn links>(mut self, links: impl Into>) -> Self { + let links: Vec<(T, &'a str)> = links.into(); self.links = links .into_iter() - .map(|(k, v)| (k.to_string(), v.to_string())) + .map(|(k, v)| (k.into(), v.to_string())) .collect(); self } @@ -128,7 +126,7 @@ pub fn about<'a, Message: Clone + 'static>( ) -> Element<'a, Message> { let spacing = crate::theme::active().cosmic().spacing; - let section = |list: &'a BTreeMap, title: &'a str| { + let section = |list: &'a Vec<(String, String)>, title: &'a str| { (!list.is_empty()).then_some({ let developers: Vec> = list.iter()