From 43fef2198a7c00ebd72c18b58509e8d060262623 Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Fri, 21 Jun 2024 20:22:27 +0300 Subject: [PATCH] some translation --- data/locales/en_US.json | 23 ++++++++++++++++++++++- src/build_ui/mod.rs | 17 +++++++++-------- src/content/mod.rs | 34 +++++++++++++++++----------------- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/data/locales/en_US.json b/data/locales/en_US.json index 52fbdf6..2712816 100644 --- a/data/locales/en_US.json +++ b/data/locales/en_US.json @@ -1,3 +1,24 @@ { - "hello": "Wassup!" + "application_name": "Fedora Kernel Manager", + "developer_name": "Cosmo", + "banner_text_no_internet": "Warning: No internet connection", + "banner_text_url_error": "Kernel Database URL Error: Please Restart!", + "loading_label_label": "Downloading Database...", + "kernel_branch_expander_row_subtitle": "Kernel Branch", + "browse_kernels_button_tooltip_text": "Browse Kernel for select branch", + "config_kernel_button_tooltip_text": "Configure Sched_EXT settings", + "config_kernel_button_tooltip_text_no_scx": "Currently running kernel doesn't support Sched-EXT", + "null_checkbutton_label": "No branch selected", + "db_load_complete": "DB load complete!", + "db_downloading": "Downloading & Parsing package DB for", + "db_download_complete": "Download Complete!", + "db_init_script_run_p1": "Running", + "db_init_script_run_p2": "init script.", + "db_init_script_successful": "init script successful.", + "db_init_script_failed": "init script failed!", + "unknown": "Unknown", + "disabled": "Disabled", + "get_current_scheduler_sched_ext_detected": "sched_ext is detected, getting scx scheduler", + "kernel_badge_branch_label": "Kernel Branch", + "kernel_badge_branch_label": "Latest Version" } \ No newline at end of file diff --git a/src/build_ui/mod.rs b/src/build_ui/mod.rs index 8cc5630..c0460b7 100644 --- a/src/build_ui/mod.rs +++ b/src/build_ui/mod.rs @@ -15,8 +15,8 @@ use std::rc::Rc; use std::{thread, time}; pub fn build_ui(app: &adw::Application) { - gtk::glib::set_prgname(Some("Fedora Kernel Manager")); - glib::set_application_name("Fedora Kernel Manager"); + gtk::glib::set_prgname(Some(t!("application_name").to_string())); + glib::set_application_name(&t!("application_name").to_string()); let internet_connected = Rc::new(RefCell::new(false)); let selected_kernel_branch: Rc> = Rc::new(RefCell::new(KernelBranch { @@ -52,7 +52,7 @@ pub fn build_ui(app: &adw::Application) { // The main loop executes the asynchronous block internet_loop_context.spawn_local(clone!(@weak window_banner => async move { while let Ok(state) = internet_loop_receiver.recv().await { - let banner_text = "Warning: No internet connection"; + let banner_text = t!("banner_text_no_internet").to_string(); if state == true { *internet_connected_status.borrow_mut()=true; if window_banner.title() == banner_text { @@ -60,8 +60,8 @@ pub fn build_ui(app: &adw::Application) { } } else { *internet_connected_status.borrow_mut()=false; - if window_banner.title() != "Kernel Database URL Error: Please Restart!" { - window_banner.set_title(banner_text); + if window_banner.title() != t!("banner_text_url_error").to_string() { + window_banner.set_title(&banner_text); window_banner.set_revealed(true) } } @@ -71,7 +71,7 @@ pub fn build_ui(app: &adw::Application) { let window_headerbar = adw::HeaderBar::builder() .title_widget( &adw::WindowTitle::builder() - .title("Fedora Kernel Manager") + .title(t!("application_name")) .build(), ) .build(); @@ -121,11 +121,12 @@ pub fn build_ui(app: &adw::Application) { let credits_window = adw::AboutWindow::builder() .application_icon(APP_ICON) - .application_name("Fedora Kernel Manager") + .application_name(t!("application_name")) .transient_for(&window) .version(VERSION) .hide_on_close(true) - .developer_name("Cosmo") + .developer_name(t!("developer_name")) + .license_type(License::Gpl20) .issue_url(APP_GITHUB.to_owned() + "/issues") .build(); diff --git a/src/content/mod.rs b/src/content/mod.rs index dd8eb44..506337c 100644 --- a/src/content/mod.rs +++ b/src/content/mod.rs @@ -45,7 +45,7 @@ pub fn content( .hexpand(true) .valign(Align::Start) .halign(Align::Center) - .label("Downloading Database...") + .label(t!("loading_label_label")) .build(); let loading_box = gtk::Box::builder() @@ -85,7 +85,7 @@ pub fn content( .build(); let kernel_branch_expander_row = adw::ExpanderRow::builder() - .subtitle("Kernel Branch") + .subtitle(t!("kernel_branch_expander_row_subtitle")) .build(); kernel_branch_expander_row.add_row(&kernel_branch_expandable( @@ -124,7 +124,7 @@ pub fn content( .margin_end(10) .height_request(50) .width_request(50) - .tooltip_text("Browse Kernel for select branch") + .tooltip_text(t!("browse_kernels_button_tooltip_text")) .hexpand(true) .build(); browse_kernels_button.add_css_class("circular"); @@ -146,7 +146,7 @@ pub fn content( .margin_end(10) .height_request(50) .width_request(50) - .tooltip_text("Configure Sched_EXT settings") + .tooltip_text(t!("config_kernel_button_tooltip_text")) .sensitive(is_scx_kernel()) .hexpand(true) .build(); @@ -154,7 +154,7 @@ pub fn content( if !is_scx_kernel() { config_kernel_button - .set_tooltip_text(Some("Currently running kernel doesn't support Sched-EXT")); + .set_tooltip_text(Some(&t!("config_kernel_button_tooltip_text_no_scx").to_string())); } config_kernel_button.connect_clicked(clone!(@weak content_stack, @weak window => move |_| { @@ -225,7 +225,7 @@ fn kernel_branch_expandable( branch_container.add_css_class("boxed-list"); let null_checkbutton = gtk::CheckButton::builder() - .label("No branch selected") + .label(t!("null_checkbutton_label")) .build(); let get_kernel_branches_loop_context = MainContext::default(); @@ -268,11 +268,11 @@ fn kernel_branch_expandable( }; *db_load_complete.borrow_mut() = true; - println!("DB load complete!") + println!("{}", t!("db_load_complete")) } } _ => { - window_banner.set_title("Kernel Database URL Error: Please Restart!"); + window_banner.set_title(t!("banner_text_url_error")); window_banner.set_revealed(true); loading_box.set_visible(false); } @@ -387,7 +387,7 @@ fn get_kernel_branches() -> Result, reqwest::Error> { .to_owned() .unwrap() .to_string(); - println!("Downloading & Parsing package DB for {}.", &branch_name); + println!("{} {}.",t!("db_downloading"), &branch_name); let branch_db = reqwest::blocking::get(branch["db_url"].as_str().to_owned().unwrap().to_string())? .text() @@ -398,11 +398,11 @@ fn get_kernel_branches() -> Result, reqwest::Error> { init_script: branch_init_script, db: branch_db, }; - println!("Download Complete!"); - println!("Running {} init script.", &branch.name); + println!("{}", t!("db_download_complete")); + println!("{} {} {}", t!("db_init_script_run_p1"), &branch.name, t!("db_init_script_run_p2")); match cmd!("bash", "-c", &branch.init_script).run() { - Ok(t) => println!("{} init script successful.", &branch.name), - _ => println!("{} init script failed.", &branch.name), + Ok(t) => println!("{} {}", &branch.name, t!("db_init_script_successful")), + _ => println!("{} {}", &branch.name, t!("db_init_script_failed")), }; kernel_branches_array.push(branch) } @@ -417,7 +417,7 @@ pub fn get_running_kernel_info() -> RunningKernelInfo { .output() { Ok(t) => String::from_utf8(t.stdout).unwrap().trim().to_owned(), - Err(_) => "Unknown".to_string(), + Err(_) => t!("unknown").to_string(), }; let version = match linux_version::linux_kernel_version() { @@ -428,7 +428,7 @@ pub fn get_running_kernel_info() -> RunningKernelInfo { format!("{}.{}.{}", t.major, t.minor, t.patch) } } - Err(_) => "Unknown".to_string(), + Err(_) => t!("unknown").to_string(), }; let info = RunningKernelInfo { @@ -450,7 +450,7 @@ fn is_scx_kernel() -> bool { } pub fn get_current_scheduler(version: String) -> String { if is_scx_kernel() { - println!("sched_ext is detected, getting scx scheduler"); + println!("{}", t!("get_current_scheduler_sched_ext_detected")); let scx_sched = match fs::read_to_string("/sys/kernel/sched_ext/root/ops") { Ok(t) => t, Err(_) => "disabled".to_string(), @@ -509,7 +509,7 @@ fn create_kernel_badges( } badge_box.append(&create_kernel_badge( - "Kernel Branch", + &t!("kernel_badge_branch_label").to_string(), &selected_kernel_branch_clone.name, "background-accent-bg", &kernel_badges_size_group,