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:
@@ -8,6 +8,7 @@ use std::{fs, io::Write};
|
||||
use color_eyre::eyre::eyre;
|
||||
use color_eyre::eyre::Context;
|
||||
use color_eyre::eyre::Result;
|
||||
use rust_i18n::t;
|
||||
use semver::Version;
|
||||
use tempfile::tempfile_in;
|
||||
use tracing::{debug, error};
|
||||
@@ -16,7 +17,7 @@ use crate::command::{CommandExt, Utf8Output};
|
||||
use crate::execution_context::ExecutionContext;
|
||||
use crate::executor::ExecutorOutput;
|
||||
use crate::terminal::{print_separator, shell};
|
||||
use crate::utils::{self, check_is_python_2_or_shim, require, require_option, which, PathExt, REQUIRE_SUDO};
|
||||
use crate::utils::{self, check_is_python_2_or_shim, get_require_sudo_string, require, require_option, which, PathExt};
|
||||
use crate::Step;
|
||||
use crate::HOME_DIR;
|
||||
use crate::{
|
||||
@@ -130,7 +131,7 @@ pub fn run_rubygems(ctx: &ExecutionContext) -> Result<()> {
|
||||
.args(["update", "--system"])
|
||||
.status_checked()?;
|
||||
} else {
|
||||
let sudo = require_option(ctx.sudo().as_ref(), REQUIRE_SUDO.to_string())?;
|
||||
let sudo = require_option(ctx.sudo().as_ref(), get_require_sudo_string())?;
|
||||
if !Path::new("/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb").exists() {
|
||||
ctx.run_type()
|
||||
.execute(sudo)
|
||||
@@ -159,7 +160,7 @@ pub fn run_haxelib_update(ctx: &ExecutionContext) -> Result<()> {
|
||||
let mut command = if directory_writable {
|
||||
ctx.run_type().execute(&haxelib)
|
||||
} else {
|
||||
let sudo = require_option(ctx.sudo().as_ref(), REQUIRE_SUDO.to_string())?;
|
||||
let sudo = require_option(ctx.sudo().as_ref(), get_require_sudo_string())?;
|
||||
let mut c = ctx.run_type().execute(sudo);
|
||||
c.arg(&haxelib);
|
||||
c
|
||||
@@ -229,8 +230,8 @@ pub fn run_aqua(ctx: &ExecutionContext) -> Result<()> {
|
||||
|
||||
print_separator("Aqua");
|
||||
if ctx.run_type().dry() {
|
||||
println!("Updating aqua ...");
|
||||
println!("Updating aqua installed cli tools ...");
|
||||
println!("{}", t!("Updating aqua ..."));
|
||||
println!("{}", t!("Updating aqua installed cli tools ..."));
|
||||
Ok(())
|
||||
} else {
|
||||
ctx.run_type().execute(&aqua).arg("update-aqua").status_checked()?;
|
||||
@@ -364,7 +365,7 @@ pub fn run_vcpkg_update(ctx: &ExecutionContext) -> Result<()> {
|
||||
let mut command = if is_root_install {
|
||||
ctx.run_type().execute(&vcpkg)
|
||||
} else {
|
||||
let sudo = require_option(ctx.sudo().as_ref(), REQUIRE_SUDO.to_string())?;
|
||||
let sudo = require_option(ctx.sudo().as_ref(), get_require_sudo_string())?;
|
||||
let mut c = ctx.run_type().execute(sudo);
|
||||
c.arg(&vcpkg);
|
||||
c
|
||||
@@ -665,7 +666,7 @@ pub fn run_tlmgr_update(ctx: &ExecutionContext) -> Result<()> {
|
||||
let mut command = if directory_writable {
|
||||
ctx.run_type().execute(&tlmgr)
|
||||
} else {
|
||||
let sudo = require_option(ctx.sudo().as_ref(), REQUIRE_SUDO.to_string())?;
|
||||
let sudo = require_option(ctx.sudo().as_ref(), get_require_sudo_string())?;
|
||||
let mut c = ctx.run_type().execute(sudo);
|
||||
c.arg(&tlmgr);
|
||||
c
|
||||
@@ -722,19 +723,22 @@ pub fn run_composer_update(ctx: &ExecutionContext) -> Result<()> {
|
||||
let composer_home = Command::new(&composer)
|
||||
.args(["global", "config", "--absolute", "--quiet", "home"])
|
||||
.output_checked_utf8()
|
||||
.map_err(|e| (SkipStep(format!("Error getting the composer directory: {e}"))))
|
||||
.map_err(|e| (SkipStep(t!("Error getting the composer directory: {error}", error = e).to_string())))
|
||||
.map(|s| PathBuf::from(s.stdout.trim()))?
|
||||
.require()?;
|
||||
|
||||
if !composer_home.is_descendant_of(&HOME_DIR) {
|
||||
return Err(SkipStep(format!(
|
||||
"Composer directory {} isn't a descendant of the user's home directory",
|
||||
composer_home.display()
|
||||
))
|
||||
return Err(SkipStep(
|
||||
t!(
|
||||
"Composer directory {composer_home} isn't a descendant of the user's home directory",
|
||||
composer_home = composer_home.display()
|
||||
)
|
||||
.to_string(),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
|
||||
print_separator("Composer");
|
||||
print_separator(t!("Composer"));
|
||||
|
||||
if ctx.config().composer_self_update() {
|
||||
cfg_if::cfg_if! {
|
||||
@@ -746,7 +750,7 @@ pub fn run_composer_update(ctx: &ExecutionContext) -> Result<()> {
|
||||
};
|
||||
|
||||
if has_update {
|
||||
let sudo = require_option(ctx.sudo().as_ref(), REQUIRE_SUDO.to_string())?;
|
||||
let sudo = require_option(ctx.sudo().as_ref(), get_require_sudo_string())?;
|
||||
ctx.run_type()
|
||||
.execute(sudo)
|
||||
.arg(&composer)
|
||||
@@ -790,9 +794,10 @@ pub fn run_dotnet_upgrade(ctx: &ExecutionContext) -> Result<()> {
|
||||
{
|
||||
Ok(output) => output,
|
||||
Err(_) => {
|
||||
return Err(SkipStep(String::from(
|
||||
"Error running `dotnet tool list`. This is expected when a dotnet runtime is installed but no SDK.",
|
||||
))
|
||||
return Err(SkipStep(
|
||||
t!("Error running `dotnet tool list`. This is expected when a dotnet runtime is installed but no SDK.")
|
||||
.to_string(),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
};
|
||||
@@ -820,7 +825,7 @@ pub fn run_dotnet_upgrade(ctx: &ExecutionContext) -> Result<()> {
|
||||
.peekable();
|
||||
|
||||
if packages.peek().is_none() {
|
||||
return Err(SkipStep(String::from("No dotnet global tools installed")).into());
|
||||
return Err(SkipStep(t!("No dotnet global tools installed").to_string()).into());
|
||||
}
|
||||
|
||||
print_separator(".NET");
|
||||
@@ -831,7 +836,7 @@ pub fn run_dotnet_upgrade(ctx: &ExecutionContext) -> Result<()> {
|
||||
.execute(&dotnet)
|
||||
.args(["tool", "update", package_name, "--global"])
|
||||
.status_checked()
|
||||
.with_context(|| format!("Failed to update .NET package {package_name}"))?;
|
||||
.with_context(|| format!("Failed to update .NET package {:?}", package_name))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -860,7 +865,7 @@ pub fn run_helix_grammars(ctx: &ExecutionContext) -> Result<()> {
|
||||
pub fn run_raco_update(ctx: &ExecutionContext) -> Result<()> {
|
||||
let raco = require("raco")?;
|
||||
|
||||
print_separator("Racket Package Manager");
|
||||
print_separator(t!("Racket Package Manager"));
|
||||
|
||||
ctx.run_type()
|
||||
.execute(raco)
|
||||
@@ -888,10 +893,10 @@ pub fn run_ghcli_extensions_upgrade(ctx: &ExecutionContext) -> Result<()> {
|
||||
let result = Command::new(&gh).args(["extensions", "list"]).output_checked_utf8();
|
||||
if result.is_err() {
|
||||
debug!("GH result {:?}", result);
|
||||
return Err(SkipStep(String::from("GH failed")).into());
|
||||
return Err(SkipStep(t!("GH failed").to_string()).into());
|
||||
}
|
||||
|
||||
print_separator("GitHub CLI Extensions");
|
||||
print_separator(t!("GitHub CLI Extensions"));
|
||||
ctx.run_type()
|
||||
.execute(&gh)
|
||||
.args(["extension", "upgrade", "--all"])
|
||||
@@ -901,7 +906,7 @@ pub fn run_ghcli_extensions_upgrade(ctx: &ExecutionContext) -> Result<()> {
|
||||
pub fn update_julia_packages(ctx: &ExecutionContext) -> Result<()> {
|
||||
let julia = require("julia")?;
|
||||
|
||||
print_separator("Julia Packages");
|
||||
print_separator(t!("Julia Packages"));
|
||||
|
||||
ctx.run_type()
|
||||
.execute(julia)
|
||||
@@ -918,7 +923,7 @@ pub fn run_helm_repo_update(ctx: &ExecutionContext) -> Result<()> {
|
||||
let mut success = true;
|
||||
let mut exec = ctx.run_type().execute(helm);
|
||||
if let Err(e) = exec.arg("repo").arg("update").status_checked() {
|
||||
error!("Updating repositories failed: {}", e);
|
||||
error!("Updating repositories failed: {e}");
|
||||
success = match exec.output_checked_utf8() {
|
||||
Ok(s) => s.stdout.contains(no_repo) || s.stderr.contains(no_repo),
|
||||
Err(e) => match e.downcast_ref::<TopgradeError>() {
|
||||
@@ -951,7 +956,7 @@ pub fn run_bob(ctx: &ExecutionContext) -> Result<()> {
|
||||
}
|
||||
|
||||
pub fn run_certbot(ctx: &ExecutionContext) -> Result<()> {
|
||||
let sudo = require_option(ctx.sudo().as_ref(), REQUIRE_SUDO.to_string())?;
|
||||
let sudo = require_option(ctx.sudo().as_ref(), get_require_sudo_string())?;
|
||||
let certbot = require("certbot")?;
|
||||
|
||||
print_separator("Certbot");
|
||||
@@ -968,7 +973,7 @@ pub fn run_certbot(ctx: &ExecutionContext) -> Result<()> {
|
||||
/// doc: https://docs.clamav.net/manual/Usage/SignatureManagement.html#freshclam
|
||||
pub fn run_freshclam(ctx: &ExecutionContext) -> Result<()> {
|
||||
let freshclam = require("freshclam")?;
|
||||
print_separator("Update ClamAV Database(FreshClam)");
|
||||
print_separator(t!("Update ClamAV Database(FreshClam)"));
|
||||
ctx.run_type().execute(freshclam).status_checked()
|
||||
}
|
||||
|
||||
@@ -1001,7 +1006,7 @@ pub fn run_lensfun_update_data(ctx: &ExecutionContext) -> Result<()> {
|
||||
const EXIT_CODE_WHEN_NO_UPDATE: i32 = 1;
|
||||
|
||||
if ctx.config().lensfun_use_sudo() {
|
||||
let sudo = require_option(ctx.sudo().as_ref(), REQUIRE_SUDO.to_string())?;
|
||||
let sudo = require_option(ctx.sudo().as_ref(), get_require_sudo_string())?;
|
||||
print_separator(SEPARATOR);
|
||||
ctx.run_type()
|
||||
.execute(sudo)
|
||||
|
||||
Reference in New Issue
Block a user