Add i18n by using rust i18n (#807)

* feat: initial i18n setup

* style: fmt

* feat: i18n support for new steps

* fix: build on Linux

* fix: build on Linux

* refactor: rm unused translation keys

---------

Co-authored-by: Steve Lau <stevelauc@outlook.com>
This commit is contained in:
Florian Nagel
2024-10-03 12:47:35 +02:00
committed by GitHub
parent c33d396489
commit 29c555c394
33 changed files with 1222 additions and 524 deletions

View File

@@ -1,54 +1,55 @@
use color_eyre::eyre::Result;
use crate::{
command::CommandExt, error::SkipStep, execution_context::ExecutionContext, terminal::print_separator, utils,
};
fn prepare_async_ssh_command(args: &mut Vec<&str>) {
args.insert(0, "ssh");
args.push("--keep");
}
pub fn ssh_step(ctx: &ExecutionContext, hostname: &str) -> Result<()> {
let ssh = utils::require("ssh")?;
let topgrade = ctx.config().remote_topgrade_path();
let mut args = vec!["-t", hostname];
if let Some(ssh_arguments) = ctx.config().ssh_arguments() {
args.extend(ssh_arguments.split_whitespace());
}
let env = format!("TOPGRADE_PREFIX={hostname}");
args.extend(["env", &env, "$SHELL", "-lc", topgrade]);
if ctx.config().run_in_tmux() && !ctx.run_type().dry() {
#[cfg(unix)]
{
prepare_async_ssh_command(&mut args);
crate::tmux::run_command(ctx, hostname, &shell_words::join(args))?;
Err(SkipStep(String::from("Remote Topgrade launched in Tmux")).into())
}
#[cfg(not(unix))]
unreachable!("Tmux execution is only implemented in Unix");
} else if ctx.config().open_remotes_in_new_terminal() && !ctx.run_type().dry() && cfg!(windows) {
prepare_async_ssh_command(&mut args);
ctx.run_type().execute("wt").args(&args).spawn()?;
Err(SkipStep(String::from("Remote Topgrade launched in an external terminal")).into())
} else {
let mut args = vec!["-t", hostname];
if let Some(ssh_arguments) = ctx.config().ssh_arguments() {
args.extend(ssh_arguments.split_whitespace());
}
let env = format!("TOPGRADE_PREFIX={hostname}");
args.extend(["env", &env, "$SHELL", "-lc", topgrade]);
print_separator(format!("Remote ({hostname})"));
println!("Connecting to {hostname}...");
ctx.run_type().execute(ssh).args(&args).status_checked()
}
}
use color_eyre::eyre::Result;
use rust_i18n::t;
use crate::{
command::CommandExt, error::SkipStep, execution_context::ExecutionContext, terminal::print_separator, utils,
};
fn prepare_async_ssh_command(args: &mut Vec<&str>) {
args.insert(0, "ssh");
args.push("--keep");
}
pub fn ssh_step(ctx: &ExecutionContext, hostname: &str) -> Result<()> {
let ssh = utils::require("ssh")?;
let topgrade = ctx.config().remote_topgrade_path();
let mut args = vec!["-t", hostname];
if let Some(ssh_arguments) = ctx.config().ssh_arguments() {
args.extend(ssh_arguments.split_whitespace());
}
let env = format!("TOPGRADE_PREFIX={hostname}");
args.extend(["env", &env, "$SHELL", "-lc", topgrade]);
if ctx.config().run_in_tmux() && !ctx.run_type().dry() {
#[cfg(unix)]
{
prepare_async_ssh_command(&mut args);
crate::tmux::run_command(ctx, hostname, &shell_words::join(args))?;
Err(SkipStep(String::from(t!("Remote Topgrade launched in Tmux"))).into())
}
#[cfg(not(unix))]
unreachable!("Tmux execution is only implemented in Unix");
} else if ctx.config().open_remotes_in_new_terminal() && !ctx.run_type().dry() && cfg!(windows) {
prepare_async_ssh_command(&mut args);
ctx.run_type().execute("wt").args(&args).spawn()?;
Err(SkipStep(String::from(t!("Remote Topgrade launched in an external terminal"))).into())
} else {
let mut args = vec!["-t", hostname];
if let Some(ssh_arguments) = ctx.config().ssh_arguments() {
args.extend(ssh_arguments.split_whitespace());
}
let env = format!("TOPGRADE_PREFIX={hostname}");
args.extend(["env", &env, "$SHELL", "-lc", topgrade]);
print_separator(format!("Remote ({hostname})"));
println!("{}", t!("Connecting to {hostname}...", hostname = hostname));
ctx.run_type().execute(ssh).args(&args).status_checked()
}
}