1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

l10n: port nice to translation + add french

This commit is contained in:
Sylvestre Ledru 2025-06-03 23:49:33 +02:00
parent 1d11f85dd2
commit b0ba545248
3 changed files with 63 additions and 24 deletions

View file

@ -1,5 +1,14 @@
nice-about = Run COMMAND with an adjusted niceness, which affects process scheduling. nice-about = Run COMMAND with an adjusted niceness, which affects process scheduling.
With no COMMAND, print the current niceness. Niceness values range from at With no COMMAND, print the current niceness. Niceness values range from
least -20 (most favorable to the process) to 19 (least favorable to the -20 (most favorable to the process) to 19 (least favorable to the process).
process). nice-usage = nice [OPTION] [COMMAND [ARG]...]
nice-usage = nice [OPTIONS] [COMMAND [ARGS]]
# 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)

View file

@ -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)

View file

@ -5,13 +5,14 @@
// spell-checker:ignore (ToDO) getpriority execvp setpriority nstr PRIO cstrs ENOENT // 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 libc::{PRIO_PROCESS, c_char, c_int, execvp};
use std::collections::HashMap;
use std::ffi::{CString, OsString}; use std::ffi::{CString, OsString};
use std::io::{Error, Write}; use std::io::{Error, Write};
use std::ptr; use std::ptr;
use clap::{Arg, ArgAction, Command}; use uucore::locale::{get_message, get_message_with_args};
use uucore::locale::get_message;
use uucore::{ use uucore::{
error::{UClapError, UResult, USimpleError, UUsageError, set_exit_code}, error::{UClapError, UResult, USimpleError, UUsageError, set_exit_code},
format_usage, show_error, format_usage, show_error,
@ -96,7 +97,6 @@ fn standardize_nice_args(mut args: impl uucore::Args) -> impl uucore::Args {
if saw_n { if saw_n {
v.push("-n".into()); v.push("-n".into());
} }
v.into_iter() 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 { if Error::last_os_error().raw_os_error().unwrap() != 0 {
return Err(USimpleError::new( return Err(USimpleError::new(
125, 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) { if !matches.contains_id(options::COMMAND) {
return Err(UUsageError::new( return Err(UUsageError::new(
125, 125,
"A command must be given with an adjustment.", get_message("nice-error-command-required-with-adjustment"),
)); ));
} }
match nstr.parse() { match nstr.parse::<i32>() {
Ok(num) => num, Ok(num) => num,
Err(e) => { Err(e) => {
return Err(USimpleError::new( return Err(USimpleError::new(
125, 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 // isn't writable. The GNU test suite checks specifically that the
// exit code when failing to write the advisory is 125, but Rust // exit code when failing to write the advisory is 125, but Rust
// will produce an exit code of 101 when it panics. // will produce an exit code of 101 when it panics.
if unsafe { libc::setpriority(PRIO_PROCESS, 0, niceness) } == -1 if unsafe { libc::setpriority(PRIO_PROCESS, 0, niceness) } == -1 {
&& write!( let warning_msg = get_message_with_args(
std::io::stderr(), "nice-warning-setpriority",
"{}: warning: setpriority: {}", HashMap::from([
uucore::util_name(), ("util_name".to_string(), uucore::util_name().to_string()),
Error::last_os_error() ("error".to_string(), Error::last_os_error().to_string()),
) ]),
.is_err() );
{
set_exit_code(125); if write!(std::io::stderr(), "{}", warning_msg).is_err() {
return Ok(()); set_exit_code(125);
return Ok(());
}
} }
let cstrs: Vec<CString> = matches let cstrs: Vec<CString> = matches
@ -172,7 +183,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
execvp(args[0], args.as_mut_ptr()); 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 { let exit_code = if Error::last_os_error().raw_os_error().unwrap() as c_int == libc::ENOENT {
127 127
} else { } else {
@ -193,7 +211,7 @@ pub fn uu_app() -> Command {
Arg::new(options::ADJUSTMENT) Arg::new(options::ADJUSTMENT)
.short('n') .short('n')
.long(options::ADJUSTMENT) .long(options::ADJUSTMENT)
.help("add N to the niceness (default is 10)") .help(get_message("nice-help-adjustment"))
.action(ArgAction::Set) .action(ArgAction::Set)
.overrides_with(options::ADJUSTMENT) .overrides_with(options::ADJUSTMENT)
.allow_hyphen_values(true), .allow_hyphen_values(true),