Skip to content

Commit 4128efa

Browse files
authored
Merge pull request #8076 from sylvestre/l10n-nice
l10n: port nice to translation + add french
2 parents 9275995 + b0ba545 commit 4128efa

File tree

3 files changed

+63
-24
lines changed

3 files changed

+63
-24
lines changed

src/uu/nice/locales/en-US.ftl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
nice-about = Run COMMAND with an adjusted niceness, which affects process scheduling.
2-
With no COMMAND, print the current niceness. Niceness values range from at
3-
least -20 (most favorable to the process) to 19 (least favorable to the
4-
process).
5-
nice-usage = nice [OPTIONS] [COMMAND [ARGS]]
2+
With no COMMAND, print the current niceness. Niceness values range from
3+
-20 (most favorable to the process) to 19 (least favorable to the process).
4+
nice-usage = nice [OPTION] [COMMAND [ARG]...]
5+
6+
# Error messages
7+
nice-error-getpriority = getpriority: { $error }
8+
nice-error-command-required-with-adjustment = A command must be given with an adjustment.
9+
nice-error-invalid-number = "{ $value }" is not a valid number: { $error }
10+
nice-warning-setpriority = { $util_name }: warning: setpriority: { $error }
11+
nice-error-execvp = execvp: { $error }
12+
13+
# Help text for command-line arguments
14+
nice-help-adjustment = add N to the niceness (default is 10)

src/uu/nice/locales/fr-FR.ftl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
nice-about = Exécute COMMANDE avec une priorité ajustée, ce qui affecte l'ordonnancement des processus.
2+
Sans COMMANDE, affiche la priorité actuelle. Les valeurs de priorité vont de
3+
-20 (plus favorable au processus) à 19 (moins favorable au processus).
4+
nice-usage = nice [OPTION] [COMMANDE [ARG]...]
5+
6+
# Messages d'erreur
7+
nice-error-command-required-with-adjustment = Une commande doit être fournie avec un ajustement.
8+
nice-error-invalid-number = "{ $value }" n'est pas un nombre valide : { $error }
9+
nice-warning-setpriority = { $util_name } : avertissement : setpriority : { $error }
10+
11+
# Texte d'aide pour les arguments de ligne de commande
12+
nice-help-adjustment = ajoute N à la priorité (par défaut 10)

src/uu/nice/src/nice.rs

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
// spell-checker:ignore (ToDO) getpriority execvp setpriority nstr PRIO cstrs ENOENT
77

8+
use clap::{Arg, ArgAction, Command};
89
use libc::{PRIO_PROCESS, c_char, c_int, execvp};
10+
use std::collections::HashMap;
911
use std::ffi::{CString, OsString};
1012
use std::io::{Error, Write};
1113
use std::ptr;
1214

13-
use clap::{Arg, ArgAction, Command};
14-
use uucore::locale::get_message;
15+
use uucore::locale::{get_message, get_message_with_args};
1516
use uucore::{
1617
error::{UClapError, UResult, USimpleError, UUsageError, set_exit_code},
1718
format_usage, show_error,
@@ -96,7 +97,6 @@ fn standardize_nice_args(mut args: impl uucore::Args) -> impl uucore::Args {
9697
if saw_n {
9798
v.push("-n".into());
9899
}
99-
100100
v.into_iter()
101101
}
102102

@@ -111,7 +111,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
111111
if Error::last_os_error().raw_os_error().unwrap() != 0 {
112112
return Err(USimpleError::new(
113113
125,
114-
format!("getpriority: {}", Error::last_os_error()),
114+
get_message_with_args(
115+
"nice-error-getpriority",
116+
HashMap::from([("error".to_string(), Error::last_os_error().to_string())]),
117+
),
115118
));
116119
}
117120

@@ -120,15 +123,21 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
120123
if !matches.contains_id(options::COMMAND) {
121124
return Err(UUsageError::new(
122125
125,
123-
"A command must be given with an adjustment.",
126+
get_message("nice-error-command-required-with-adjustment"),
124127
));
125128
}
126-
match nstr.parse() {
129+
match nstr.parse::<i32>() {
127130
Ok(num) => num,
128131
Err(e) => {
129132
return Err(USimpleError::new(
130133
125,
131-
format!("\"{nstr}\" is not a valid number: {e}"),
134+
get_message_with_args(
135+
"nice-error-invalid-number",
136+
HashMap::from([
137+
("value".to_string(), nstr.clone()),
138+
("error".to_string(), e.to_string()),
139+
]),
140+
),
132141
));
133142
}
134143
}
@@ -147,17 +156,19 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
147156
// isn't writable. The GNU test suite checks specifically that the
148157
// exit code when failing to write the advisory is 125, but Rust
149158
// will produce an exit code of 101 when it panics.
150-
if unsafe { libc::setpriority(PRIO_PROCESS, 0, niceness) } == -1
151-
&& write!(
152-
std::io::stderr(),
153-
"{}: warning: setpriority: {}",
154-
uucore::util_name(),
155-
Error::last_os_error()
156-
)
157-
.is_err()
158-
{
159-
set_exit_code(125);
160-
return Ok(());
159+
if unsafe { libc::setpriority(PRIO_PROCESS, 0, niceness) } == -1 {
160+
let warning_msg = get_message_with_args(
161+
"nice-warning-setpriority",
162+
HashMap::from([
163+
("util_name".to_string(), uucore::util_name().to_string()),
164+
("error".to_string(), Error::last_os_error().to_string()),
165+
]),
166+
);
167+
168+
if write!(std::io::stderr(), "{}", warning_msg).is_err() {
169+
set_exit_code(125);
170+
return Ok(());
171+
}
161172
}
162173

163174
let cstrs: Vec<CString> = matches
@@ -172,7 +183,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
172183
execvp(args[0], args.as_mut_ptr());
173184
}
174185

175-
show_error!("execvp: {}", Error::last_os_error());
186+
show_error!(
187+
"{}",
188+
get_message_with_args(
189+
"nice-error-execvp",
190+
HashMap::from([("error".to_string(), Error::last_os_error().to_string())])
191+
)
192+
);
193+
176194
let exit_code = if Error::last_os_error().raw_os_error().unwrap() as c_int == libc::ENOENT {
177195
127
178196
} else {
@@ -193,7 +211,7 @@ pub fn uu_app() -> Command {
193211
Arg::new(options::ADJUSTMENT)
194212
.short('n')
195213
.long(options::ADJUSTMENT)
196-
.help("add N to the niceness (default is 10)")
214+
.help(get_message("nice-help-adjustment"))
197215
.action(ArgAction::Set)
198216
.overrides_with(options::ADJUSTMENT)
199217
.allow_hyphen_values(true),

0 commit comments

Comments
 (0)