From 737bb24daceef281aba3dfefa9b161cf2a34d0a5 Mon Sep 17 00:00:00 2001 From: musiclover Date: Sun, 3 Apr 2022 20:22:58 +0200 Subject: Make strings translatable in rust source code --- src/ui/task_details.rs | 27 ++++++++++++++------------- src/ui/tasks_page.rs | 5 +++-- src/ui/window.rs | 16 +++++++++------- 3 files changed, 26 insertions(+), 22 deletions(-) (limited to 'src/ui') diff --git a/src/ui/task_details.rs b/src/ui/task_details.rs index c45d561..62438d3 100755 --- a/src/ui/task_details.rs +++ b/src/ui/task_details.rs @@ -15,6 +15,7 @@ // along with this program. If not, see . use adw::subclass::prelude::*; +use gettextrs::*; use glib::clone; use gtk::subclass::prelude::*; use gtk::{glib, prelude::*, CompositeTemplate}; @@ -163,7 +164,7 @@ impl FurTaskDetails { gtk::DialogFlags::MODAL, gtk::MessageType::Question, gtk::ButtonsType::OkCancel, - "Edit Task", + &format!("{}", &gettext("Edit Task")), ); dialog.set_use_markup(true); @@ -173,9 +174,9 @@ impl FurTaskDetails { task_name_edit.set_text(&task.task_name); let labels_box = gtk::Box::new(gtk::Orientation::Horizontal, 5); labels_box.set_homogeneous(true); - let start_label = gtk::Label::new(Some("Start")); + let start_label = gtk::Label::new(Some(&gettext("Start"))); start_label.add_css_class("title-4"); - let stop_label = gtk::Label::new(Some("Stop")); + let stop_label = gtk::Label::new(Some(&gettext("Stop"))); stop_label.add_css_class("title-4"); let times_box = gtk::Box::new(gtk::Orientation::Horizontal, 5); times_box.set_homogeneous(true); @@ -194,26 +195,26 @@ impl FurTaskDetails { stop_time_edit.set_text(&stop_time_w_year); let instructions = gtk::Label::new(Some( - "*Use the format MMM DD YYYY HH:MM:SS")); + &gettext("*Use the format MMM DD YYYY HH:MM:SS"))); if !settings_manager::get_bool("show-seconds") { - instructions.set_text("*Use the format MMM DD YYYY HH:MM"); + instructions.set_text(&gettext("*Use the format MMM DD YYYY HH:MM")); } instructions.set_visible(false); instructions.add_css_class("error_message"); let time_error = gtk::Label::new(Some( - "*Start time cannot be later than stop time.")); + &gettext("*Start time cannot be later than stop time."))); time_error.set_visible(false); time_error.add_css_class("error_message"); let future_error = gtk::Label::new(Some( - "*Time cannot be in the future.")); + &gettext("*Time cannot be in the future."))); future_error.set_visible(false); future_error.add_css_class("error_message"); let delete_task_btn = gtk::Button::new(); delete_task_btn.set_icon_name("user-trash-symbolic"); - delete_task_btn.set_tooltip_text(Some("Delete task")); + delete_task_btn.set_tooltip_text(Some(&gettext("Delete task"))); delete_task_btn.set_hexpand(false); delete_task_btn.set_vexpand(false); delete_task_btn.set_halign(gtk::Align::End); @@ -239,7 +240,7 @@ impl FurTaskDetails { gtk::DialogFlags::MODAL, gtk::MessageType::Question, gtk::ButtonsType::OkCancel, - Some("Delete task?"), + Some(&format!("{}", &gettext("Delete task?"))), ); delete_confirmation.connect_response(clone!( @@ -462,12 +463,12 @@ impl FurTaskDetails { gtk::DialogFlags::MODAL, gtk::MessageType::Warning, gtk::ButtonsType::None, - Some("Delete All?"), + Some(&format!("{}", &gettext("Delete All?"))), ); - dialog.set_secondary_text(Some("This will delete all occurrences of this task on this day.")); + dialog.set_secondary_text(Some(&gettext("This will delete all occurrences of this task on this day."))); dialog.add_buttons(&[ - ("Delete", gtk::ResponseType::Accept), - ("Cancel", gtk::ResponseType::Reject) + (&gettext("Delete"), gtk::ResponseType::Accept), + (&gettext("Cancel"), gtk::ResponseType::Reject) ]); dialog.connect_response(clone!(@strong dialog => move |_,resp|{ diff --git a/src/ui/tasks_page.rs b/src/ui/tasks_page.rs index 9f0aed3..23439eb 100755 --- a/src/ui/tasks_page.rs +++ b/src/ui/tasks_page.rs @@ -16,6 +16,7 @@ use adw::subclass::prelude::*; use adw::prelude::{PreferencesPageExt, PreferencesGroupExt}; +use gettextrs::*; use gtk::subclass::prelude::*; use gtk::{glib, prelude::*}; use chrono::{DateTime, Local, Duration}; @@ -142,9 +143,9 @@ impl FurTasksPage { for i in 0..uniq_date_list.len() { let group = FurTasksGroup::new(); if uniq_date_list[i] == today { - group.set_title("Today") + group.set_title(&gettext("Today")) } else if uniq_date_list[i] == yesterday{ - group.set_title("Yesterday") + group.set_title(&gettext("Yesterday")) } else { group.set_title(&uniq_date_list[i]) } diff --git a/src/ui/window.rs b/src/ui/window.rs index f49c8b2..36efb90 100755 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -15,6 +15,7 @@ // along with this program. If not, see . use adw::subclass::prelude::AdwApplicationWindowImpl; +use gettextrs::*; use gtk::prelude::*; use gtk::subclass::prelude::*; use gtk::{gio, glib, CompositeTemplate}; @@ -174,9 +175,9 @@ impl FurtheranceWindow { gtk::DialogFlags::MODAL, gtk::MessageType::Error, gtk::ButtonsType::Ok, - Some("No Task Name"), + Some(&format!("{}", &gettext("No Task Name"))), ); - dialog.set_secondary_text(Some("Enter a task name to start the timer.")); + dialog.set_secondary_text(Some(&gettext("Enter a task name to start the timer."))); dialog.show(); dialog.connect_response(clone!(@strong dialog => move |_,_|{ @@ -282,19 +283,20 @@ impl FurtheranceWindow { let m = (idle_time / 60) - (h * 60); let s = idle_time - (m * 60); let idle_time_str = format!( - "You have been idle for {:02}:{:02}:{:02}.\nWould you like to discard that time, or continue the clock?", - h, m, s); + "{}{:02}:{:02}:{:02}{}", gettext("You have been idle for "), h, m, s, + gettext(".\nWould you like to discard that time, or continue the clock?") + ); let dialog = gtk::MessageDialog::with_markup( Some(self), gtk::DialogFlags::MODAL, gtk::MessageType::Warning, gtk::ButtonsType::None, - Some("Edit Task"), + Some(&format!("{}", &gettext("Edit Task"))), ); dialog.add_buttons(&[ - ("Discard", gtk::ResponseType::Reject), - ("Continue", gtk::ResponseType::Accept) + (&gettext("Discard"), gtk::ResponseType::Reject), + (&gettext("Continue"), gtk::ResponseType::Accept) ]); dialog.set_secondary_text(Some(&idle_time_str)); -- cgit 1.4.1 From fe9f283041ed8544aebae6739b6761390dc9fb27 Mon Sep 17 00:00:00 2001 From: musiclover Date: Mon, 4 Apr 2022 14:37:47 +0200 Subject: Small fix in UI Move Delete button to the right in the Delete All? dialog --- src/ui/task_details.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ui') diff --git a/src/ui/task_details.rs b/src/ui/task_details.rs index 62438d3..7e306e8 100755 --- a/src/ui/task_details.rs +++ b/src/ui/task_details.rs @@ -467,8 +467,8 @@ impl FurTaskDetails { ); dialog.set_secondary_text(Some(&gettext("This will delete all occurrences of this task on this day."))); dialog.add_buttons(&[ - (&gettext("Delete"), gtk::ResponseType::Accept), - (&gettext("Cancel"), gtk::ResponseType::Reject) + (&gettext("Cancel"), gtk::ResponseType::Reject), + (&gettext("Delete"), gtk::ResponseType::Accept) ]); dialog.connect_response(clone!(@strong dialog => move |_,resp|{ -- cgit 1.4.1