[gnome-tour] i18n: move more string to UI files
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tour] i18n: move more string to UI files
- Date: Sat, 29 Jan 2022 11:15:14 +0000 (UTC)
commit 8afee947e77e33a48016c3842c91195bfcc85f55
Author: Bilal Elmoussaoui <belmouss redhat com>
Date: Sat Jan 29 12:14:58 2022 +0100
i18n: move more string to UI files
This only leaves us with only one translatable string defined on a rust file,
due to the low gettext/rust support...
data/resources/ui/window.ui | 6 ++++++
po/POTFILES.in | 3 +--
src/widgets/image_page.rs | 16 +++++++++++-----
src/widgets/paginator.rs | 28 +++++-----------------------
src/widgets/window.rs | 12 ++++++++++++
5 files changed, 35 insertions(+), 30 deletions(-)
---
diff --git a/data/resources/ui/window.ui b/data/resources/ui/window.ui
index 5834e80..6cd2016 100644
--- a/data/resources/ui/window.ui
+++ b/data/resources/ui/window.ui
@@ -5,6 +5,12 @@
<property name="default-height">720</property>
<property name="content">
<object class="PaginatorWidget" id="paginator">
+ <child>
+ <object class="ImagePageWidget" id="welcome_page">
+ <property name="resource-uri">/org/gnome/Tour/welcome.svg</property>
+ <property name="head" translatable="yes">Start the Tour</property>
+ </object>
+ </child>
<child>
<object class="ImagePageWidget">
<property name="resource-uri">/org/gnome/Tour/overview.svg</property>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d1835ff..0c744ee 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,6 +2,5 @@ data/org.gnome.Tour.desktop.in.in
data/org.gnome.Tour.metainfo.xml.in.in
data/resources/ui/paginator.ui
data/resources/ui/window.ui
-src/widgets/image_page.rs
-src/widgets/paginator.rs
+src/widgets/window.rs
src/main.rs
diff --git a/src/widgets/image_page.rs b/src/widgets/image_page.rs
index c4e26a1..d49d97d 100644
--- a/src/widgets/image_page.rs
+++ b/src/widgets/image_page.rs
@@ -7,12 +7,13 @@ mod imp {
use glib::once_cell::sync::Lazy;
use glib::{ParamFlags, ParamSpec, ParamSpecString, Value};
use gtk::glib::once_cell::sync::OnceCell;
+ use std::cell::RefCell;
#[derive(Debug, Default)]
pub struct ImagePageWidget {
pub(super) resource_uri: OnceCell<String>,
pub(super) head: OnceCell<String>,
- pub(super) body: OnceCell<String>,
+ pub(super) body: RefCell<String>,
pub(super) picture: gtk::Picture,
}
@@ -105,7 +106,7 @@ mod imp {
"Body",
"The body of the page",
None,
- ParamFlags::READWRITE | ParamFlags::CONSTRUCT_ONLY,
+ ParamFlags::READWRITE | ParamFlags::CONSTRUCT,
),
]
});
@@ -124,8 +125,9 @@ mod imp {
self.head.set(head).unwrap();
}
"body" => {
- let body = value.get().unwrap();
- self.body.set(body).unwrap();
+ if let Some(body) = value.get::<Option<String>>().unwrap() {
+ self.body.replace(body);
+ }
}
_ => unimplemented!(),
}
@@ -135,7 +137,7 @@ mod imp {
match pspec.name() {
"resource-uri" => self.resource_uri.get().to_value(),
"head" => self.head.get().to_value(),
- "body" => self.body.get().to_value(),
+ "body" => self.body.borrow().to_value(),
_ => unimplemented!(),
}
}
@@ -158,4 +160,8 @@ impl ImagePageWidget {
])
.unwrap()
}
+
+ pub fn set_body(&self, body: &str) {
+ self.set_property("body", &body);
+ }
}
diff --git a/src/widgets/paginator.rs b/src/widgets/paginator.rs
index d3fa71b..602aa30 100644
--- a/src/widgets/paginator.rs
+++ b/src/widgets/paginator.rs
@@ -1,5 +1,3 @@
-use crate::{utils::i18n_f, widgets::ImagePageWidget};
-use gettextrs::gettext;
use gtk::prelude::*;
use gtk::{
gdk,
@@ -9,8 +7,7 @@ use gtk::{
mod imp {
use super::*;
- use std::cell::Cell;
- use std::cell::RefCell;
+ use std::cell::{Cell, RefCell};
#[derive(Debug, gtk::CompositeTemplate)]
#[template(resource = "/org/gnome/Tour/ui/paginator.ui")]
@@ -35,7 +32,7 @@ mod imp {
start_btn: TemplateChild::default(),
next_btn: TemplateChild::default(),
previous_btn: TemplateChild::default(),
- pages: RefCell::new(Vec::new()),
+ pages: RefCell::default(),
current_page: Cell::new(0),
going_backward: Cell::new(false),
}
@@ -72,21 +69,6 @@ mod imp {
obj.update_position();
}));
- let name = glib::os_info("NAME").unwrap_or_else(|| "GNOME".into());
- let version = glib::os_info("VERSION").unwrap_or_else(|| "".into());
-
- let body = i18n_f(
- // Translators: The following string is formated as "Learn about new and essential features
in GNOME 3.36" for example
- "Learn about the key features in {name} {version}.",
- &[("name", &name), ("version", &version)],
- );
- let welcome_page = ImagePageWidget::new(
- "/org/gnome/Tour/welcome.svg",
- gettext("Start the Tour"),
- body,
- );
- obj.add_page(Some(-1), welcome_page);
-
let controller = gtk::EventControllerKey::new();
controller.connect_key_pressed(clone!(@weak obj => @default-return gtk::Inhibit(true), move
|_controller, keyval, _keycode, _state| {
if keyval == gdk::Key::Right {
@@ -115,7 +97,7 @@ mod imp {
if !self.carousel.is_bound() {
self.parent_add_child(buildable, builder, child, type_);
} else {
- buildable.add_page(None, child.clone().downcast::<gtk::Widget>().unwrap());
+ buildable.add_page(child.clone().downcast::<gtk::Widget>().unwrap());
}
}
}
@@ -151,10 +133,10 @@ impl PaginatorWidget {
Some(())
}
- pub fn add_page(&self, at: Option<i32>, page: impl IsA<gtk::Widget>) {
+ pub fn add_page(&self, page: impl IsA<gtk::Widget>) {
let imp = self.imp();
let page_nr = imp.pages.borrow().len();
- imp.carousel.insert(&page, at.unwrap_or(page_nr as i32));
+ imp.carousel.insert(&page, page_nr as i32);
imp.pages.borrow_mut().push(page.upcast());
self.update_position();
diff --git a/src/widgets/window.rs b/src/widgets/window.rs
index dabc690..f0ee7c9 100644
--- a/src/widgets/window.rs
+++ b/src/widgets/window.rs
@@ -1,3 +1,4 @@
+use crate::utils::i18n_f;
use adw::prelude::*;
use gtk::subclass::prelude::*;
use gtk::{gio, glib};
@@ -16,6 +17,8 @@ mod imp {
pub struct Window {
#[template_child]
pub(super) paginator: TemplateChild<PaginatorWidget>,
+ #[template_child]
+ pub(super) welcome_page: TemplateChild<ImagePageWidget>,
}
#[glib::object_subclass]
@@ -42,6 +45,15 @@ mod imp {
if config::PROFILE == "Devel" {
widget.add_css_class("devel");
}
+ let name = glib::os_info("NAME").unwrap_or_else(|| "GNOME".into());
+ let version = glib::os_info("VERSION").unwrap_or_else(|| "".into());
+
+ let body = i18n_f(
+ // Translators: The following string is formated as "Learn about new and essential features
in GNOME 3.36" for example
+ "Learn about the key features in {name} {version}.",
+ &[("name", &name), ("version", &version)],
+ );
+ self.welcome_page.set_body(&body);
self.parent_constructed(widget);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]