1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27: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.
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)

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
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::<i32>() {
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<CString> = 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),