Skip to content

Commit 42e91d0

Browse files
committed
Added translation to interactive steps using single characters to prompt for action
1 parent 35e1771 commit 42e91d0

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

locales/app.yml

+19
Original file line numberDiff line numberDiff line change
@@ -507,3 +507,22 @@ _version: 2
507507
en: "Dry running"
508508
"Topgrade Upgraded":
509509
en: "Topgrade Upgraded"
510+
"OK":
511+
en: "OK"
512+
"FAILED":
513+
en: "FAILED"
514+
"IGNORED":
515+
en: "IGNORED"
516+
"SKIPPED":
517+
en: "SKIPPED"
518+
# 'Y' and 'N' have to stay the same characters. Eg for German the translation would look sth like "(Y) Ja / (N) Nein"
519+
"(Y)es/(N)o":
520+
en: "(Y)es/(N)o"
521+
# '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"
522+
"Retry? (y)es/(N)o/(s)hell/(q)uit":
523+
en: "Retry? (y)es/(N)o/(s)hell/(q)uit"
524+
"Failed to run shell":
525+
en: "Failed to run shell"
526+
# '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"
527+
"\n(R)eboot\n(S)hell\n(Q)uit":
528+
en: "\n(R)eboot\n(S)hell\n(Q)uit"

src/main.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,7 @@ fn run() -> Result<()> {
481481
}
482482

483483
if config.keep_at_end() {
484-
// TODO: Refactor this to make it easier to implement i18n
485-
// Ie use the first letter from the translations, not a hardcoded literal
486-
print_info("\n(R)eboot\n(S)hell\n(Q)uit");
484+
print_info(t!("\n(R)eboot\n(S)hell\n(Q)uit"));
487485
loop {
488486
match get_key() {
489487
Ok(Key::Char('s')) | Ok(Key::Char('S')) => {

src/terminal.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,10 @@ impl Terminal {
175175
"{}: {}\n",
176176
key,
177177
match result {
178-
// TODO: Add i18n
179-
StepResult::Success => format!("{}", style("OK").bold().green()),
180-
StepResult::Failure => format!("{}", style("FAILED").bold().red()),
181-
StepResult::Ignored => format!("{}", style("IGNORED").bold().yellow()),
182-
StepResult::Skipped(reason) => format!("{}: {}", style("SKIPPED").bold().blue(), reason),
178+
StepResult::Success => format!("{}", style(t!("OK")).bold().green()),
179+
StepResult::Failure => format!("{}", style(t!("FAILED")).bold().red()),
180+
StepResult::Ignored => format!("{}", style(t!("IGNORED")).bold().yellow()),
181+
StepResult::Skipped(reason) => format!("{}: {}", style(t!("SKIPPED")).bold().blue(), reason),
183182
}
184183
))
185184
.ok();
@@ -190,8 +189,7 @@ impl Terminal {
190189
self.term
191190
.write_fmt(format_args!(
192191
"{}",
193-
// TODO: Implement i18n for this using the first character from the translated key
194-
style(format!("{question} (y)es/(N)o",)).yellow().bold()
192+
style(format!("{question} {}", t!("(Y)es/(N)o"))).yellow().bold()
195193
))
196194
.ok();
197195

@@ -217,8 +215,7 @@ impl Terminal {
217215
self.notify_desktop(format!("{}", t!("{step_name} failed", step_name = step_name)), None);
218216
}
219217

220-
// TODO: Implement i18n for this using the first character from the translated key
221-
let prompt_inner = style(format!("{}Retry? (y)es/(N)o/(s)hell/(q)uit", self.prefix))
218+
let prompt_inner = style(format!("{}{}", self.prefix, t!("Retry? (y)es/(N)o/(s)hell/(q)uit")))
222219
.yellow()
223220
.bold();
224221

@@ -232,7 +229,7 @@ impl Terminal {
232229
"\n\n{}\n",
233230
t!("Dropping you to shell. Fix what you need and then exit the shell.")
234231
);
235-
if let Err(err) = run_shell().context("Failed to run shell") {
232+
if let Err(err) = run_shell().context(t!("Failed to run shell")) {
236233
self.term.write_fmt(format_args!("{err:?}\n{prompt_inner}")).ok();
237234
} else {
238235
break Ok(true);

0 commit comments

Comments
 (0)