Commit d3576ed0 authored by Eisha Chen-yen-su's avatar Eisha Chen-yen-su

fractal-gtk: Wrap all translatable strings

This wraps all the translatable strings in the source code with
gettext functions.

Closes https://gitlab.gnome.org/World/fractal/issues/89
parent ea0dfa00
extern crate gettextrs;
use self::gettextrs::gettext;
use app::App;
use appop::RoomPanel;
......@@ -90,7 +94,7 @@ pub fn backend_loop(rx: Receiver<BKResponse>) {
}
Ok(BKResponse::DirectorySearch(rooms)) => {
if rooms.len() == 0 {
let error = "No rooms found".to_string();
let error = gettext("No rooms found");
APPOP!(show_error, (error));
APPOP!(enable_directory_search);
}
......@@ -154,7 +158,7 @@ pub fn backend_loop(rx: Receiver<BKResponse>) {
Ok(BKResponse::NewRoomError(err, internal_id)) => {
println!("ERROR: {:?}", err);
let error = "Can't create the room, try again".to_string();
let error = gettext("Can't create the room, try again");
let panel = RoomPanel::NoRoom;
APPOP!(remove_room, (internal_id));
APPOP!(show_error, (error));
......@@ -162,23 +166,23 @@ pub fn backend_loop(rx: Receiver<BKResponse>) {
},
Ok(BKResponse::JoinRoomError(err)) => {
println!("ERROR: {:?}", err);
let error = format!("Can't join to the room, try again.");
let error = format!("{}", gettext("Can't join to the room, try again."));
let panel = RoomPanel::NoRoom;
APPOP!(show_error, (error));
APPOP!(room_panel, (panel));
},
Ok(BKResponse::LoginError(_)) => {
let error = "Can't login, try again".to_string();
let error = gettext("Can't login, try again");
let st = AppState::Login;
APPOP!(show_error, (error));
APPOP!(set_state, (st));
},
Ok(BKResponse::SendMsgError(_)) => {
let error = "Error sending message".to_string();
let error = gettext("Error sending message");
APPOP!(show_error, (error));
}
Ok(BKResponse::DirectoryError(_)) => {
let error = "Error searching for rooms".to_string();
let error = gettext("Error searching for rooms");
APPOP!(show_error, (error));
APPOP!(enable_directory_search);
}
......
extern crate gtk;
extern crate gettextrs;
use self::gtk::prelude::*;
use self::gettextrs::gettext;
use appop::AppOp;
use globals;
......@@ -13,14 +16,14 @@ impl AppOp {
let dialog = gtk::AboutDialog::new();
dialog.set_logo_icon_name(globals::APP_ID);
dialog.set_comments("A Matrix.org client for GNOME");
dialog.set_copyright("© 2017–2018 Daniel García Moreno, et al.");
dialog.set_comments(gettext("A Matrix.org client for GNOME").as_str());
dialog.set_copyright(gettext("© 2017–2018 Daniel García Moreno, et al.").as_str());
dialog.set_license_type(gtk::License::Gpl30);
dialog.set_modal(true);
dialog.set_version(env!("CARGO_PKG_VERSION"));
dialog.set_program_name("Fractal");
dialog.set_website("https://wiki.gnome.org/Fractal");
dialog.set_website_label("Learn more about Fractal");
dialog.set_website_label(gettext("Learn more about Fractal").as_str());
dialog.set_transient_for(&window);
dialog.set_artists(&[
......@@ -35,7 +38,7 @@ impl AppOp {
"Julian Sparber",
]);
dialog.add_credit_section("Name by", &["Regina Bíró"]);
dialog.add_credit_section(gettext("Name by").as_str(), &["Regina Bíró"]);
dialog.show();
}
......
extern crate gdk;
extern crate gdk_pixbuf;
extern crate gtk;
extern crate gettextrs;
use self::gtk::prelude::*;
use self::gettextrs::gettext;
use appop::AppOp;
use backend::BKCommand;
......@@ -47,7 +49,7 @@ impl AppOp {
.expect("Can't find main_window in ui file.");
let img = gtk::Image::new();
let dialog = gtk::Dialog::new_with_buttons(
Some("Image from Clipboard"),
Some(gettext("Image from Clipboard").as_str()),
Some(&window),
gtk::DialogFlags::MODAL|
gtk::DialogFlags::USE_HEADER_BAR|
......@@ -61,8 +63,8 @@ impl AppOp {
if let Some(hbar) = dialog.get_header_bar() {
let bar = hbar.downcast::<gtk::HeaderBar>().unwrap();
let closebtn = gtk::Button::new_with_label("Cancel");
let okbtn = gtk::Button::new_with_label("Send");
let closebtn = gtk::Button::new_with_label(gettext("Cancel").as_str());
let okbtn = gtk::Button::new_with_label(gettext("Send").as_str());
okbtn.get_style_context().unwrap().add_class("suggested-action");
bar.set_show_close_button(false);
......
extern crate gtk;
extern crate gettextrs;
use self::gtk::prelude::*;
use self::gettextrs::gettext;
use appop::AppOp;
......@@ -55,7 +57,7 @@ impl AppOp {
let btn = self.ui.builder
.get_object::<gtk::Button>("directory_search_button")
.expect("Can't find directory_search_button in ui file.");
btn.set_label("Searching...");
btn.set_label(gettext("Searching...").as_str());
btn.set_sensitive(false);
if !more {
......@@ -92,7 +94,7 @@ impl AppOp {
let btn = self.ui.builder
.get_object::<gtk::Button>("directory_search_button")
.expect("Can't find directory_search_button in ui file.");
btn.set_label("Search");
btn.set_label(gettext("Search").as_str());
btn.set_sensitive(true);
}
}
extern crate gtk;
extern crate gettextrs;
use self::gtk::prelude::*;
use self::gettextrs::gettext;
use appop::AppOp;
use appop::member::SearchType;
......@@ -132,9 +134,10 @@ impl AppOp {
if let Some(aroom) = self.active_room.clone() {
if let Some(r) = self.rooms.get(&aroom) {
if let &Some(ref name) = &r.name {
title.set_text(&format!("Invite to {}", name));
let sentence_template = gettext("Invite to {name}");
title.set_text(&sentence_template.replace("{name}", name));
} else {
title.set_text("Invite");
title.set_text(gettext("Invite").as_str());
}
}
}
......@@ -203,14 +206,16 @@ impl AppOp {
.expect("Can't find invite_dialog in ui file.");
let room_name = r.name.clone().unwrap_or_default();
let title = format!("Join {}?", room_name);
let title = format!("{} {}?", gettext("Join"), room_name);
let secondary;
if let Some(ref sender) = r.inv_sender {
let sender_name = sender.get_alias();
secondary = format!("You've been invited to join to <b>{}</b> room by <b>{}</b>",
room_name, sender_name);
let sentence_template = gettext("You've been invited to join to <b>{room_name}</b> room by <b>{sender_name}</b>");
secondary = sentence_template.replace("{room_name}", room_name.as_str())
.replace("{sender_name}", sender_name.as_str());
} else {
secondary = format!("You've been invited to join to <b>{}</b>", room_name);
let sentence_template = gettext("You've been invited to join to <b>{room_name}</b>");
secondary = sentence_template.replace("{room_name}", room_name.as_str());
}
dialog.set_property_text(Some(&title));
......
extern crate gtk;
extern crate gettextrs;
use self::gtk::prelude::*;
use self::gettextrs::gettext;
use appop::AppOp;
use appop::state::AppState;
......@@ -101,11 +104,11 @@ impl AppOp {
if username.clone().unwrap_or_default().is_empty() ||
password.clone().unwrap_or_default().is_empty() {
login_error.set_text("Invalid username or password");
login_error.set_text(gettext("Invalid username or password").as_str());
login_error.show();
return;
} else {
login_error.set_text("Unknown Error");
login_error.set_text(gettext("Unknown Error").as_str());
login_error.hide();
}
......@@ -159,7 +162,7 @@ impl AppOp {
};
if password != passconf {
self.show_error("Passwords didn't match, try again".to_string());
self.show_error(gettext("Passwords didn't match, try again"));
return;
}
......
extern crate gtk;
extern crate gettextrs;
use self::gtk::prelude::*;
use self::gettextrs::gettext;
use std::collections::HashMap;
......@@ -82,7 +84,9 @@ impl AppOp {
}
if members.len() > self.member_limit {
let newlabel = format!("and {} more", members.len() - self.member_limit);
let sentence_template = gettext("and {member_count} more");
let newlabel = sentence_template.replace("{member_count}",
&(members.len() - self.member_limit).to_string());
self.more_members_btn.set_label(&newlabel);
self.more_members_btn.show();
} else {
......
extern crate gtk;
extern crate comrak;
extern crate chrono;
extern crate gettextrs;
use self::gtk::prelude::*;
use self::chrono::prelude::*;
use self::comrak::{markdown_to_html, ComrakOptions};
use self::gettextrs::gettext;
use app::InternalCommand;
use appop::AppOp;
......@@ -164,7 +166,7 @@ impl AppOp {
};
if last == LastViewed::Inline && msg.sender != self.uid.clone().unwrap_or_default() {
let divider: gtk::ListBoxRow = widgets::divider::new("New Messages");
let divider: gtk::ListBoxRow = widgets::divider::new(gettext("New Messages").as_str());
match msgpos {
MsgPos::Bottom => messages.add(&divider),
MsgPos::Top => messages.insert(&divider, 2),
......@@ -309,7 +311,7 @@ impl AppOp {
Some(&window),
gtk::FileChooserAction::Open);
let btn = dialog.add_button("Select", 1);
let btn = dialog.add_button(gettext("Select").as_str(), 1);
btn.get_style_context().unwrap().add_class("suggested-action");
let backend = self.backend.clone();
......
extern crate gtk;
extern crate gettextrs;
use std::sync::mpsc::Sender;
use std::collections::HashMap;
use gio::ApplicationExt;
use self::gtk::prelude::*;
use self::gettextrs::gettext;
use backend::BKCommand;
use backend;
......@@ -99,7 +101,7 @@ impl AppOp {
ui: ui,
gtk_app: app,
load_more_spn: gtk::Spinner::new(),
more_members_btn: gtk::Button::new_with_label("Load more members"),
more_members_btn: gtk::Button::new_with_label(gettext("Load more members").as_str()),
backend: tx,
internal: itx,
autoscroll: true,
......
extern crate gtk;
extern crate gdk_pixbuf;
extern crate rand;
extern crate gettextrs;
use self::gtk::prelude::*;
use self::gettextrs::gettext;
use appop::AppOp;
use appop::AppState;
......@@ -248,7 +250,7 @@ impl AppOp {
.expect("Can't find leave_room_dialog in ui file.");
if let Some(r) = self.rooms.get(&self.active_room.clone().unwrap_or_default()) {
dialog.set_property_text(Some(&format!("Leave {}?", r.name.clone().unwrap_or_default())));
dialog.set_property_text(Some(&format!("{} {}?", gettext("Leave"), r.name.clone().unwrap_or_default())));
dialog.present();
}
}
......@@ -567,10 +569,10 @@ impl AppOp {
};
let name = match n {
0 => String::from("EMPTY ROOM"),
0 => gettext("EMPTY ROOM"),
1 => String::from(m1),
2 => format!("{} and {}", m1, m2),
_ => format!("{} and Others", m1),
2 => format!("{} {} {}", m1, gettext("and"), m2),
_ => format!("{} {}", m1, gettext("and Others")),
};
r.name = Some(name);
......
extern crate gettextrs;
use self::gettextrs::gettext;
use appop::AppOp;
use backend::BKCommand;
......@@ -6,7 +9,7 @@ use backend::BKCommand;
impl AppOp {
pub fn initial_sync(&self, show: bool) {
if show {
self.inapp_notify("Syncing, this could take a while");
self.inapp_notify(&gettext("Syncing, this could take a while"));
} else {
self.hide_inapp_notify();
}
......
extern crate gtk;
extern crate gdk_pixbuf;
extern crate pango;
extern crate gettextrs;
use self::gdk_pixbuf::Pixbuf;
use self::gtk::prelude::*;
use self::gettextrs::gettext;
use types::Room;
......@@ -89,7 +91,7 @@ impl<'a> RoomBox<'a> {
idw.set_halign(gtk::Align::Start);
idw.set_valign(gtk::Align::Start);
let joinbtn = gtk::Button::new_with_label("Join");
let joinbtn = gtk::Button::new_with_label(gettext("Join").as_str());
let rid = r.id.clone();
let backend = self.op.backend.clone();
joinbtn.connect_clicked(move |_| {
......
......@@ -3,6 +3,7 @@ extern crate url;
extern crate gtk;
extern crate pango;
extern crate gdk;
extern crate gettextrs;
use glib;
use self::gdk::DragContextExtManual;
......@@ -10,6 +11,7 @@ use self::gdk::DragContextExtManual;
use self::url::Url;
use std::collections::HashMap;
use self::gtk::prelude::*;
use self::gettextrs::gettext;
use widgets::roomrow::RoomRow;
use types::Room;
......@@ -428,10 +430,13 @@ impl RoomList {
let widget = gtk::Box::new(gtk::Orientation::Vertical, 6);
let baseu = get_url(url);
let inv = RGroup::new(&baseu, "Invites", "You don't have any invitations");
let fav = RGroup::new(&baseu, "Favorites", "Drag and drop rooms here to \
add them to your favorites");
let rooms = RGroup::new(&baseu, "Rooms", "You don't have any rooms yet");
let inv = RGroup::new(&baseu, gettext("Invites").as_str(),
gettext("You don't have any invitations").as_str());
let fav = RGroup::new(&baseu, gettext("Favorites").as_str(),
gettext("Drag and drop rooms here to \
add them to your favorites").as_str());
let rooms = RGroup::new(&baseu, gettext("Rooms").as_str(),
gettext("You don't have any rooms yet").as_str());
let rl = RoomList {
baseu,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment