Skip to content

Commit

Permalink
Added translation to interactive steps using single characters to pro…
Browse files Browse the repository at this point in the history
…mpt for action
  • Loading branch information
Mastermindaxe committed Jul 1, 2024
1 parent 35e1771 commit 732f29e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
19 changes: 19 additions & 0 deletions locales/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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')) => {
Expand Down
17 changes: 7 additions & 10 deletions src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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);
Expand Down

0 comments on commit 732f29e

Please sign in to comment.