From b0ba545248deef74351c712c9915cbb22535c91f Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 3 Jun 2025 23:49:33 +0200 Subject: [PATCH] l10n: port nice to translation + add french --- src/uu/nice/locales/en-US.ftl | 17 +++++++--- src/uu/nice/locales/fr-FR.ftl | 12 ++++++++ src/uu/nice/src/nice.rs | 58 +++++++++++++++++++++++------------ 3 files changed, 63 insertions(+), 24 deletions(-) create mode 100644 src/uu/nice/locales/fr-FR.ftl diff --git a/src/uu/nice/locales/en-US.ftl b/src/uu/nice/locales/en-US.ftl index d243ef94e..fad0b19e5 100644 --- a/src/uu/nice/locales/en-US.ftl +++ b/src/uu/nice/locales/en-US.ftl @@ -1,5 +1,14 @@ nice-about = Run COMMAND with an adjusted niceness, which affects process scheduling. - With no COMMAND, print the current niceness. Niceness values range from at - least -20 (most favorable to the process) to 19 (least favorable to the - process). -nice-usage = nice [OPTIONS] [COMMAND [ARGS]] + With no COMMAND, print the current niceness. Niceness values range from + -20 (most favorable to the process) to 19 (least favorable to the process). +nice-usage = nice [OPTION] [COMMAND [ARG]...] + +# Error messages +nice-error-getpriority = getpriority: { $error } +nice-error-command-required-with-adjustment = A command must be given with an adjustment. +nice-error-invalid-number = "{ $value }" is not a valid number: { $error } +nice-warning-setpriority = { $util_name }: warning: setpriority: { $error } +nice-error-execvp = execvp: { $error } + +# Help text for command-line arguments +nice-help-adjustment = add N to the niceness (default is 10) diff --git a/src/uu/nice/locales/fr-FR.ftl b/src/uu/nice/locales/fr-FR.ftl new file mode 100644 index 000000000..5154424cf --- /dev/null +++ b/src/uu/nice/locales/fr-FR.ftl @@ -0,0 +1,12 @@ +nice-about = Exécute COMMANDE avec une priorité ajustée, ce qui affecte l'ordonnancement des processus. + Sans COMMANDE, affiche la priorité actuelle. Les valeurs de priorité vont de + -20 (plus favorable au processus) à 19 (moins favorable au processus). +nice-usage = nice [OPTION] [COMMANDE [ARG]...] + +# Messages d'erreur +nice-error-command-required-with-adjustment = Une commande doit être fournie avec un ajustement. +nice-error-invalid-number = "{ $value }" n'est pas un nombre valide : { $error } +nice-warning-setpriority = { $util_name } : avertissement : setpriority : { $error } + +# Texte d'aide pour les arguments de ligne de commande +nice-help-adjustment = ajoute N à la priorité (par défaut 10) diff --git a/src/uu/nice/src/nice.rs b/src/uu/nice/src/nice.rs index bb86d7778..943e72c7c 100644 --- a/src/uu/nice/src/nice.rs +++ b/src/uu/nice/src/nice.rs @@ -5,13 +5,14 @@ // spell-checker:ignore (ToDO) getpriority execvp setpriority nstr PRIO cstrs ENOENT +use clap::{Arg, ArgAction, Command}; use libc::{PRIO_PROCESS, c_char, c_int, execvp}; +use std::collections::HashMap; use std::ffi::{CString, OsString}; use std::io::{Error, Write}; use std::ptr; -use clap::{Arg, ArgAction, Command}; -use uucore::locale::get_message; +use uucore::locale::{get_message, get_message_with_args}; use uucore::{ error::{UClapError, UResult, USimpleError, UUsageError, set_exit_code}, format_usage, show_error, @@ -96,7 +97,6 @@ fn standardize_nice_args(mut args: impl uucore::Args) -> impl uucore::Args { if saw_n { v.push("-n".into()); } - v.into_iter() } @@ -111,7 +111,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if Error::last_os_error().raw_os_error().unwrap() != 0 { return Err(USimpleError::new( 125, - format!("getpriority: {}", Error::last_os_error()), + get_message_with_args( + "nice-error-getpriority", + HashMap::from([("error".to_string(), Error::last_os_error().to_string())]), + ), )); } @@ -120,15 +123,21 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if !matches.contains_id(options::COMMAND) { return Err(UUsageError::new( 125, - "A command must be given with an adjustment.", + get_message("nice-error-command-required-with-adjustment"), )); } - match nstr.parse() { + match nstr.parse::() { Ok(num) => num, Err(e) => { return Err(USimpleError::new( 125, - format!("\"{nstr}\" is not a valid number: {e}"), + get_message_with_args( + "nice-error-invalid-number", + HashMap::from([ + ("value".to_string(), nstr.clone()), + ("error".to_string(), e.to_string()), + ]), + ), )); } } @@ -147,17 +156,19 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // isn't writable. The GNU test suite checks specifically that the // exit code when failing to write the advisory is 125, but Rust // will produce an exit code of 101 when it panics. - if unsafe { libc::setpriority(PRIO_PROCESS, 0, niceness) } == -1 - && write!( - std::io::stderr(), - "{}: warning: setpriority: {}", - uucore::util_name(), - Error::last_os_error() - ) - .is_err() - { - set_exit_code(125); - return Ok(()); + if unsafe { libc::setpriority(PRIO_PROCESS, 0, niceness) } == -1 { + let warning_msg = get_message_with_args( + "nice-warning-setpriority", + HashMap::from([ + ("util_name".to_string(), uucore::util_name().to_string()), + ("error".to_string(), Error::last_os_error().to_string()), + ]), + ); + + if write!(std::io::stderr(), "{}", warning_msg).is_err() { + set_exit_code(125); + return Ok(()); + } } let cstrs: Vec = matches @@ -172,7 +183,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { execvp(args[0], args.as_mut_ptr()); } - show_error!("execvp: {}", Error::last_os_error()); + show_error!( + "{}", + get_message_with_args( + "nice-error-execvp", + HashMap::from([("error".to_string(), Error::last_os_error().to_string())]) + ) + ); + let exit_code = if Error::last_os_error().raw_os_error().unwrap() as c_int == libc::ENOENT { 127 } else { @@ -193,7 +211,7 @@ pub fn uu_app() -> Command { Arg::new(options::ADJUSTMENT) .short('n') .long(options::ADJUSTMENT) - .help("add N to the niceness (default is 10)") + .help(get_message("nice-help-adjustment")) .action(ArgAction::Set) .overrides_with(options::ADJUSTMENT) .allow_hyphen_values(true),