From 732f29e98cfe9e208b57dc271cc999e36c5b9599 Mon Sep 17 00:00:00 2001 From: Mastermindaxe Date: Mon, 1 Jul 2024 15:19:44 +0200 Subject: [PATCH] Added translation to interactive steps using single characters to prompt for action --- locales/app.yml | 19 +++++++++++++++++++ src/main.rs | 2 +- src/terminal.rs | 17 +++++++---------- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/locales/app.yml b/locales/app.yml index 1132f044..03a35d08 100644 --- a/locales/app.yml +++ b/locales/app.yml @@ -507,3 +507,22 @@ _version: 2 en: "Dry running" "Topgrade Upgraded": en: "Topgrade Upgraded" +"OK": + en: "OK" +"FAILED": + en: "FAILED" +"IGNORED": + en: "IGNORED" +"SKIPPED": + en: "SKIPPED" +# 'Y' and 'N' have to stay the same characters. Eg for German the translation would look sth like "(Y) Ja / (N) Nein" +"(Y)es/(N)o": + en: "(Y)es/(N)o" +# 'y', 'N', 's', 'q' have to stay the same throughout all translations. Eg German would look like "(R) Wiederholen / (N) Nein / (s) Konsole / (q) Beenden" +"Retry? (y)es/(N)o/(s)hell/(q)uit": + en: "Retry? (y)es/(N)o/(s)hell/(q)uit" +"Failed to run shell": + en: "Failed to run shell" +# 'R', 'S', 'Q' have to stay the same throughout all translations. Eg German would look like "\n(R) Neustarten\n(S) Konsole\n(Q) Beenden" +"\n(R)eboot\n(S)hell\n(Q)uit": + en: "\n(R)eboot\n(S)hell\n(Q)uit" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 30954d1a..b797c4c8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -483,7 +483,7 @@ fn run() -> Result<()> { if config.keep_at_end() { // TODO: Refactor this to make it easier to implement i18n // Ie use the first letter from the translations, not a hardcoded literal - print_info("\n(R)eboot\n(S)hell\n(Q)uit"); + print_info(t!("\n(R)eboot\n(S)hell\n(Q)uit")); loop { match get_key() { Ok(Key::Char('s')) | Ok(Key::Char('S')) => { diff --git a/src/terminal.rs b/src/terminal.rs index d4624b5d..8ff927f6 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -175,11 +175,10 @@ impl Terminal { "{}: {}\n", key, match result { - // TODO: Add i18n - StepResult::Success => format!("{}", style("OK").bold().green()), - StepResult::Failure => format!("{}", style("FAILED").bold().red()), - StepResult::Ignored => format!("{}", style("IGNORED").bold().yellow()), - StepResult::Skipped(reason) => format!("{}: {}", style("SKIPPED").bold().blue(), reason), + StepResult::Success => format!("{}", style(t!("OK")).bold().green()), + StepResult::Failure => format!("{}", style(t!("FAILED")).bold().red()), + StepResult::Ignored => format!("{}", style(t!("IGNORED")).bold().yellow()), + StepResult::Skipped(reason) => format!("{}: {}", style(t!("SKIPPED")).bold().blue(), reason), } )) .ok(); @@ -190,8 +189,7 @@ impl Terminal { self.term .write_fmt(format_args!( "{}", - // TODO: Implement i18n for this using the first character from the translated key - style(format!("{question} (y)es/(N)o",)).yellow().bold() + style(format!("{question} {}", t!("(Y)es/(N)o"))).yellow().bold() )) .ok(); @@ -217,8 +215,7 @@ impl Terminal { self.notify_desktop(format!("{}", t!("{step_name} failed", step_name = step_name)), None); } - // TODO: Implement i18n for this using the first character from the translated key - let prompt_inner = style(format!("{}Retry? (y)es/(N)o/(s)hell/(q)uit", self.prefix)) + let prompt_inner = style(format!("{}{}", self.prefix, t!("Retry? (y)es/(N)o/(s)hell/(q)uit"))) .yellow() .bold(); @@ -232,7 +229,7 @@ impl Terminal { "\n\n{}\n", t!("Dropping you to shell. Fix what you need and then exit the shell.") ); - if let Err(err) = run_shell().context("Failed to run shell") { + if let Err(err) = run_shell().context(t!("Failed to run shell")) { self.term.write_fmt(format_args!("{err:?}\n{prompt_inner}")).ok(); } else { break Ok(true);