mirror of
https://github.com/jwinterm/grim.git
synced 2026-10-24 08:28:33 +02:00
ui: update i18n lib
This commit is contained in:
@@ -25,7 +25,7 @@ use crate::gui::Colors;
|
||||
|
||||
/// Type of button.
|
||||
pub enum FilePickContentType {
|
||||
Button, ItemButton(CornerRadius), Tab
|
||||
Button(String), ItemButton(CornerRadius), Tab
|
||||
}
|
||||
|
||||
/// Button to pick file and parse its data into text.
|
||||
@@ -116,9 +116,9 @@ impl FilePickContent {
|
||||
}
|
||||
} else {
|
||||
// Draw button to pick file.
|
||||
match self.content_type {
|
||||
FilePickContentType::Button => {
|
||||
let text = format!("{} {}", ARCHIVE_BOX, t!("choose_file"));
|
||||
match &self.content_type {
|
||||
FilePickContentType::Button(text) => {
|
||||
let text = format!("{} {}", ARCHIVE_BOX, text);
|
||||
let text_color = Colors::blue();
|
||||
let fill = Colors::white_or_black(false);
|
||||
View::colored_text_button(ui, text, text_color, fill, || {
|
||||
@@ -126,7 +126,7 @@ impl FilePickContent {
|
||||
});
|
||||
}
|
||||
FilePickContentType::ItemButton(r) => {
|
||||
View::item_button(ui, r, ARCHIVE_BOX, Some(Colors::blue()), || {
|
||||
View::item_button(ui, r.clone(), ARCHIVE_BOX, Some(Colors::blue()), || {
|
||||
self.on_file_pick(pick, cb);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -458,7 +458,7 @@ impl KeyboardContent {
|
||||
/// Draw input button.
|
||||
fn input_button_ui(&mut self, s: &str, translate: bool, ui: &mut egui::Ui) -> Rect {
|
||||
let value = if translate {
|
||||
t!(format!("keyboard.{}", s).as_str(), locale = Self::input_locale().as_str())
|
||||
t!(format!("keyboard.{}", s), locale = Self::input_locale().as_str()).into()
|
||||
} else {
|
||||
s.to_string()
|
||||
};
|
||||
|
||||
@@ -104,8 +104,8 @@ impl Modal {
|
||||
}
|
||||
|
||||
/// Set title text on [`Modal`] creation.
|
||||
pub fn title(mut self, title: String) -> Self {
|
||||
self.title = Some(title.to_uppercase());
|
||||
pub fn title(mut self, title: impl Into<String>) -> Self {
|
||||
self.title = Some(title.into().to_uppercase());
|
||||
self
|
||||
}
|
||||
|
||||
@@ -157,11 +157,11 @@ impl Modal {
|
||||
}
|
||||
|
||||
/// Set title text for current opened [`Modal`].
|
||||
pub fn set_title(title: String) {
|
||||
pub fn set_title(title: impl Into<String>) {
|
||||
let mut w_state = MODAL_STATE.write();
|
||||
if w_state.modal.is_some() {
|
||||
let mut modal = w_state.modal.clone().unwrap();
|
||||
modal.title = Some(title.to_uppercase());
|
||||
modal.title = Some(title.into().to_uppercase());
|
||||
w_state.modal = Some(modal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,9 +173,9 @@ impl ConnectionsContent {
|
||||
DOTS_THREE_CIRCLE
|
||||
};
|
||||
let status_text = format!("{} {}", status_icon, if has_error {
|
||||
t!("error")
|
||||
t!("error").into()
|
||||
} else {
|
||||
Node::get_sync_status_text()
|
||||
Node::get_sync_status_text().into()
|
||||
});
|
||||
View::ellipsize_text(ui, status_text, 15.0, Colors::text(false));
|
||||
ui.add_space(1.0);
|
||||
|
||||
@@ -140,7 +140,7 @@ impl NetworkContent {
|
||||
disabled_node_ui(ui);
|
||||
} else if Node::get_stats().is_none() || Node::is_restarting() ||
|
||||
Node::is_stopping() {
|
||||
NetworkContent::loading_ui(ui, None);
|
||||
NetworkContent::loading_ui(ui, None::<String>);
|
||||
} else {
|
||||
self.node_tab_content.tab_ui(ui, cb);
|
||||
}
|
||||
@@ -278,14 +278,14 @@ impl NetworkContent {
|
||||
|
||||
// Setup values for title panel.
|
||||
let title_text = self.node_tab_content.get_type().title();
|
||||
let subtitle_text = Node::get_sync_status_text();
|
||||
let subtitle_text = Node::get_sync_status_text().into();
|
||||
let not_syncing = Node::not_syncing() && !Node::data_dir_changing();
|
||||
let title_content = if show_settings {
|
||||
TitleContentType::Title(t!("settings"))
|
||||
TitleContentType::Title(t!("settings").into())
|
||||
} else if !show_connections {
|
||||
TitleContentType::WithSubTitle(title_text, subtitle_text, !not_syncing)
|
||||
} else {
|
||||
TitleContentType::Title(t!("network.connections"))
|
||||
TitleContentType::Title(t!("network.connections").into())
|
||||
};
|
||||
|
||||
// Draw title panel.
|
||||
@@ -313,7 +313,7 @@ impl NetworkContent {
|
||||
}
|
||||
|
||||
/// Content to draw on loading.
|
||||
pub fn loading_ui(ui: &mut egui::Ui, text: Option<String>) {
|
||||
pub fn loading_ui(ui: &mut egui::Ui, text: Option<impl Into<String>>) {
|
||||
match text {
|
||||
None => {
|
||||
ui.centered_and_justified(|ui| {
|
||||
|
||||
@@ -392,9 +392,9 @@ impl P2PSetup {
|
||||
};
|
||||
// Select modal title.
|
||||
let modal_title = match peer_type {
|
||||
PeerType::Allowed => t!("network_settings.allow_list"),
|
||||
PeerType::Denied => t!("network_settings.deny_list"),
|
||||
PeerType::Preferred => t!("network_settings.favourites"),
|
||||
PeerType::Allowed => t!("network_settings.allow_list").into(),
|
||||
PeerType::Denied => t!("network_settings.deny_list").into(),
|
||||
PeerType::Preferred => t!("network_settings.favourites").into(),
|
||||
_ => DNS_SEEDS_TITLE.to_string()
|
||||
};
|
||||
// Show modal to add peer.
|
||||
|
||||
@@ -32,10 +32,10 @@ pub enum NodeTabType {
|
||||
impl NodeTabType {
|
||||
pub fn title(&self) -> String {
|
||||
match *self {
|
||||
NodeTabType::Info => { t!("network.node") }
|
||||
NodeTabType::Metrics => { t!("network.metrics") }
|
||||
NodeTabType::Mining => { t!("network.mining") }
|
||||
NodeTabType::Settings => { t!("network.settings") }
|
||||
NodeTabType::Info => t!("network.node").into(),
|
||||
NodeTabType::Metrics => t!("network.metrics").into(),
|
||||
NodeTabType::Mining => t!("network.mining").into(),
|
||||
NodeTabType::Settings => t!("network.settings").into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ impl Default for InterfaceSettingsContent {
|
||||
let locale = if let Some(lang) = AppConfig::locale() {
|
||||
lang
|
||||
} else {
|
||||
rust_i18n::locale()
|
||||
rust_i18n::locale().to_string()
|
||||
};
|
||||
Self {
|
||||
locale,
|
||||
|
||||
@@ -244,7 +244,7 @@ impl NetworkSettingsContent {
|
||||
(url, Colors::title(false), CLOUD_CHECK, t!("network_settings.enabled"))
|
||||
} else {
|
||||
(
|
||||
t!("enter_url"),
|
||||
t!("enter_url").into(),
|
||||
Colors::inactive_text(),
|
||||
CLOUD_SLASH,
|
||||
t!("network_settings.disabled")
|
||||
|
||||
+27
-20
@@ -119,8 +119,8 @@ impl View {
|
||||
}
|
||||
|
||||
/// Cut long text with ﹍ character.
|
||||
fn ellipsize(text: String, size: f32, color: Color32) -> LayoutJob {
|
||||
let mut job = LayoutJob::single_section(text, TextFormat {
|
||||
fn ellipsize(text: impl Into<String>, size: f32, color: Color32) -> LayoutJob {
|
||||
let mut job = LayoutJob::single_section(text.into(), TextFormat {
|
||||
font_id: FontId::proportional(size), color, ..Default::default()
|
||||
});
|
||||
job.wrap = TextWrapping {
|
||||
@@ -133,12 +133,16 @@ impl View {
|
||||
}
|
||||
|
||||
/// Draw ellipsized text.
|
||||
pub fn ellipsize_text(ui: &mut egui::Ui, text: String, size: f32, color: Color32) {
|
||||
pub fn ellipsize_text(ui: &mut egui::Ui, text: impl Into<String>, size: f32, color: Color32) {
|
||||
ui.label(Self::ellipsize(text, size, color));
|
||||
}
|
||||
|
||||
/// Draw animated ellipsized text.
|
||||
pub fn animate_text(ui: &mut egui::Ui, text: String, size: f32, color: Color32, animate: bool) {
|
||||
pub fn animate_text(ui: &mut egui::Ui,
|
||||
text: impl Into<String>,
|
||||
size: f32,
|
||||
color: Color32,
|
||||
animate: bool) {
|
||||
// Setup text color animation if needed.
|
||||
let (dark, bright) = (0.3, 1.0);
|
||||
let color_factor = if animate {
|
||||
@@ -287,10 +291,10 @@ impl View {
|
||||
}
|
||||
|
||||
/// Draw [`Button`] with specified background fill color and default text color.
|
||||
pub fn button(ui: &mut egui::Ui, text: String, fill: Color32, action: impl FnOnce()) {
|
||||
let br = Self::button_resp(ui, text, Colors::text_button(), fill);
|
||||
pub fn button(ui: &mut egui::Ui, text: impl Into<String>, fill: Color32, cb: impl FnOnce()) {
|
||||
let br = Self::button_resp(ui, text.into(), Colors::text_button(), fill);
|
||||
if br.clicked() {
|
||||
action();
|
||||
cb();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,16 +324,16 @@ impl View {
|
||||
|
||||
/// Draw gold action [`Button`].
|
||||
pub fn action_button(ui: &mut egui::Ui,
|
||||
text: String, action: impl FnOnce()) {
|
||||
Self::colored_text_button(ui, text, Colors::title(true), Colors::gold(), action);
|
||||
text: impl Into<String>, action: impl FnOnce()) {
|
||||
Self::colored_text_button(ui, text.into(), Colors::title(true), Colors::gold(), action);
|
||||
}
|
||||
|
||||
/// Draw [`Button`] with specified background fill color and ui at callback.
|
||||
pub fn button_ui(ui: &mut egui::Ui,
|
||||
text: String,
|
||||
text: impl Into<String>,
|
||||
fill: Color32,
|
||||
action: impl FnOnce(&mut egui::Ui)) {
|
||||
let button_text = Self::ellipsize(text.to_uppercase(), 17.0, Colors::text_button());
|
||||
let button_text = Self::ellipsize(text.into().to_uppercase(), 17.0, Colors::text_button());
|
||||
let br = Button::new(button_text)
|
||||
.stroke(Self::default_stroke())
|
||||
.fill(fill)
|
||||
@@ -443,7 +447,7 @@ impl View {
|
||||
/// where is r = (top_left, top_right, bottom_left, bottom_right).
|
||||
/// | VALUE |
|
||||
/// | label |
|
||||
pub fn label_box(ui: &mut egui::Ui, text: String, label: String, r: [bool; 4]) {
|
||||
pub fn label_box(ui: &mut egui::Ui, v: impl Into<String>, l: impl Into<String>, r: [bool; 4]) {
|
||||
let rect = ui.available_rect_before_wrap();
|
||||
|
||||
// Create background shape.
|
||||
@@ -464,7 +468,7 @@ impl View {
|
||||
ui.style_mut().spacing.item_spacing.y = -3.0;
|
||||
|
||||
// Draw box value.
|
||||
let mut job = LayoutJob::single_section(text, TextFormat {
|
||||
let mut job = LayoutJob::single_section(v.into(), TextFormat {
|
||||
font_id: FontId::proportional(17.0),
|
||||
color: Colors::white_or_black(true),
|
||||
..Default::default()
|
||||
@@ -478,7 +482,7 @@ impl View {
|
||||
ui.label(job);
|
||||
|
||||
// Draw box label.
|
||||
ui.label(RichText::new(label).color(Colors::gray()).size(15.0));
|
||||
ui.label(RichText::new(l).color(Colors::gray()).size(15.0));
|
||||
});
|
||||
ui.add_space(2.0);
|
||||
});
|
||||
@@ -524,10 +528,10 @@ impl View {
|
||||
}
|
||||
|
||||
/// Draw the button that looks like checkbox with callback on check.
|
||||
pub fn checkbox(ui: &mut egui::Ui, checked: bool, text: String, action: impl FnOnce()) {
|
||||
pub fn checkbox(ui: &mut egui::Ui, checked: bool, text: impl Into<String>, cb: impl FnOnce()) {
|
||||
let (text_value, color) = match checked {
|
||||
true => (format!("{} {}", CHECK_SQUARE, text), Colors::text_button()),
|
||||
false => (format!("{} {}", SQUARE, text), Colors::checkbox())
|
||||
true => (format!("{} {}", CHECK_SQUARE, text.into()), Colors::text_button()),
|
||||
false => (format!("{} {}", SQUARE, text.into()), Colors::checkbox())
|
||||
};
|
||||
|
||||
let br = Button::new(RichText::new(text_value).size(17.0).color(color))
|
||||
@@ -537,18 +541,21 @@ impl View {
|
||||
.ui(ui)
|
||||
.on_hover_cursor(CursorIcon::PointingHand);
|
||||
if br.clicked() {
|
||||
action();
|
||||
cb();
|
||||
}
|
||||
}
|
||||
|
||||
/// Show a [`RadioButton`]. It is selected if `*current_value == selected_value`.
|
||||
/// If clicked, `selected_value` is assigned to `*current_value`.
|
||||
pub fn radio_value<T: PartialEq>(ui: &mut egui::Ui, current: &mut T, value: T, text: String) {
|
||||
pub fn radio_value<T: PartialEq>(ui: &mut egui::Ui,
|
||||
current: &mut T,
|
||||
value: T,
|
||||
text: impl Into<String>) {
|
||||
ui.scope(|ui| {
|
||||
// Setup background color.
|
||||
ui.visuals_mut().widgets.inactive.bg_fill = Colors::fill_deep();
|
||||
// Draw radio button.
|
||||
let mut response = ui.radio(*current == value, text)
|
||||
let mut response = ui.radio(*current == value, text.into())
|
||||
.on_hover_cursor(CursorIcon::PointingHand);
|
||||
if response.clicked() && *current != value {
|
||||
*current = value;
|
||||
|
||||
@@ -424,7 +424,7 @@ impl WalletsContent {
|
||||
// Setup title.
|
||||
let title_content = if show_wallet && (!dual_panel
|
||||
|| (dual_panel && !show_list)) && !creating_wallet && !showing_settings {
|
||||
let title = self.wallet_content.title();
|
||||
let title = self.wallet_content.title().into();
|
||||
let subtitle = self.wallets.selected().unwrap().get_config().name;
|
||||
TitleType::Single(TitleContentType::WithSubTitle(title, subtitle, false))
|
||||
} else {
|
||||
@@ -434,11 +434,11 @@ impl WalletsContent {
|
||||
t!("wallets.add")
|
||||
} else {
|
||||
t!("wallets.title")
|
||||
};
|
||||
}.into();
|
||||
let dual_title = !showing_settings && !creating_wallet &&
|
||||
show_wallet && dual_panel;
|
||||
if dual_title {
|
||||
let title = self.wallet_content.title();
|
||||
let title = self.wallet_content.title().into();
|
||||
let subtitle = self.wallets.selected().unwrap().get_config().name;
|
||||
let wallet_title_content = TitleContentType::WithSubTitle(title, subtitle, false);
|
||||
TitleType::Dual(TitleContentType::Title(title_text), wallet_title_content)
|
||||
|
||||
@@ -213,7 +213,7 @@ impl WalletCreationContent {
|
||||
.color(Colors::red()));
|
||||
ui.add_space(10.0);
|
||||
} else {
|
||||
ui.label(RichText::new(&t!("wallets.not_valid_phrase"))
|
||||
ui.label(RichText::new(t!("wallets.not_valid_phrase"))
|
||||
.size(16.0)
|
||||
.color(Colors::red()));
|
||||
ui.add_space(4.0);
|
||||
@@ -303,7 +303,7 @@ impl WalletCreationContent {
|
||||
let (next_text, text_color, bg_color) = if self.step == Step::SetupConnection {
|
||||
(format!("{} {}", CHECK, t!("complete")), Colors::title(true), Colors::gold())
|
||||
} else {
|
||||
(t!("continue"), Colors::green(), Colors::white_or_black(false))
|
||||
(t!("continue").into(), Colors::green(), Colors::white_or_black(false))
|
||||
};
|
||||
|
||||
// Show next step button.
|
||||
|
||||
@@ -30,7 +30,7 @@ pub struct AddWalletModal {
|
||||
impl Default for AddWalletModal {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name_edit: t!("wallets.default_wallet"),
|
||||
name_edit: t!("wallets.default_wallet").into(),
|
||||
pass_edit: "".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ impl AccountContent {
|
||||
let account = wallet.get_config().account;
|
||||
let default_acc_label = WalletConfig::DEFAULT_ACCOUNT_LABEL.to_string();
|
||||
let acc_label = if account == default_acc_label {
|
||||
t!("wallets.default_account")
|
||||
t!("wallets.default_account").into()
|
||||
} else {
|
||||
account.to_owned()
|
||||
};
|
||||
|
||||
@@ -111,7 +111,7 @@ impl WalletAccountsContent {
|
||||
// Show account name.
|
||||
let default_acc_label = WalletConfig::DEFAULT_ACCOUNT_LABEL.to_string();
|
||||
let acc_label = if acc.label == default_acc_label {
|
||||
t!("wallets.default_account")
|
||||
t!("wallets.default_account").into()
|
||||
} else {
|
||||
acc.label.to_owned()
|
||||
};
|
||||
|
||||
@@ -313,7 +313,7 @@ impl Default for WalletContent {
|
||||
|
||||
impl WalletContent {
|
||||
/// Get title based on current navigation state.
|
||||
pub fn title(&self) -> String {
|
||||
pub fn title(&self) -> impl Into<String> {
|
||||
if self.account_content.qr_scan_showing() {
|
||||
t!("scan_qr")
|
||||
} else if self.account_content.list_content.is_some() {
|
||||
@@ -595,26 +595,26 @@ fn sync_progress_ui(ui: &mut egui::Ui, wallet: &Wallet) {
|
||||
let info_progress = wallet.info_sync_progress();
|
||||
|
||||
if wallet.files_moving() {
|
||||
t!("moving_files")
|
||||
t!("moving_files").into()
|
||||
} else if wallet.is_closing() {
|
||||
t!("wallets.wallet_closing")
|
||||
t!("wallets.wallet_closing").into()
|
||||
} else if int_node && !int_ready {
|
||||
t!("wallets.node_loading", "settings" => GEAR_FINE)
|
||||
t!("wallets.node_loading", "settings" => GEAR_FINE).into()
|
||||
} else if wallet.is_repairing() {
|
||||
let repair_progress = wallet.repairing_progress();
|
||||
if repair_progress == 0 {
|
||||
t!("wallets.wallet_checking")
|
||||
t!("wallets.wallet_checking").into()
|
||||
} else {
|
||||
format!("{}: {}%", t!("wallets.wallet_checking"), repair_progress)
|
||||
}
|
||||
} else if info_progress != 100 {
|
||||
if info_progress == 0 {
|
||||
t!("wallets.wallet_loading")
|
||||
t!("wallets.wallet_loading").into()
|
||||
} else {
|
||||
format!("{}: {}%", t!("wallets.wallet_loading"), info_progress)
|
||||
}
|
||||
} else {
|
||||
t!("wallets.tx_loading")
|
||||
t!("wallets.tx_loading").into()
|
||||
}
|
||||
};
|
||||
ui.label(RichText::new(text).size(16.0).color(Colors::inactive_text()));
|
||||
|
||||
@@ -46,7 +46,9 @@ impl Default for MessageInputContent {
|
||||
message_edit: "".to_string(),
|
||||
parse_error: false,
|
||||
scan_qr_content: None,
|
||||
file_pick_button: FilePickContent::new(FilePickContentType::Button),
|
||||
file_pick_button: FilePickContent::new(
|
||||
FilePickContentType::Button(t!("choose_file").into())
|
||||
),
|
||||
proof_content: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ impl PaymentProofContent {
|
||||
pub fn new(proof_text: Option<String>) -> Self {
|
||||
Self {
|
||||
input_edit: proof_text.unwrap_or("".to_string()),
|
||||
pick_button: FilePickContent::new(FilePickContentType::Button),
|
||||
pick_button: FilePickContent::new(FilePickContentType::Button(t!("file").into())),
|
||||
parse_error: false,
|
||||
validation_result: None,
|
||||
}
|
||||
@@ -159,7 +159,7 @@ impl PaymentProofContent {
|
||||
ui.add_space(6.0);
|
||||
ui.vertical_centered(|ui| {
|
||||
let (desc_text, color) = if tx.data.tx_type == TxLogEntryType::TxReceived {
|
||||
(t!("wallets.payment_proof_valid"), Colors::green())
|
||||
(t!("wallets.payment_proof_valid").into(), Colors::green())
|
||||
} else {
|
||||
(format!("{}:", t!("wallets.payment_proof")), Colors::inactive_text())
|
||||
};
|
||||
|
||||
@@ -573,7 +573,7 @@ impl WalletTransactionsContent {
|
||||
}
|
||||
|
||||
/// Draw awaiting balance item content.
|
||||
fn awaiting_item_ui(ui: &mut egui::Ui, amount: u64, label: String) {
|
||||
fn awaiting_item_ui(ui: &mut egui::Ui, amount: u64, label: impl Into<String>) {
|
||||
let rect = ui.available_rect_before_wrap();
|
||||
View::line(ui, LinePosition::TOP, &rect, Colors::item_stroke());
|
||||
ui.add_space(4.0);
|
||||
|
||||
+1
-2
@@ -14,6 +14,7 @@
|
||||
|
||||
#[macro_use]
|
||||
extern crate rust_i18n;
|
||||
rust_i18n::i18n!("locales");
|
||||
|
||||
use eframe::NativeOptions;
|
||||
use egui::{Context, Stroke, Theme};
|
||||
@@ -32,8 +33,6 @@ use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::View;
|
||||
use crate::node::Node;
|
||||
|
||||
i18n!("locales");
|
||||
|
||||
mod node;
|
||||
mod wallet;
|
||||
mod tor;
|
||||
|
||||
+1
-1
@@ -456,7 +456,7 @@ impl Node {
|
||||
}
|
||||
|
||||
/// Get synchronization status i18n text.
|
||||
pub fn get_sync_status_text() -> String {
|
||||
pub fn get_sync_status_text() -> impl Into<String> {
|
||||
if Node::data_dir_changing() {
|
||||
return t!("moving_files");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user