Skip to content

Commit 55a733a

Browse files
committed
translate remaining "naked" user-facing strings
1 parent 489d7de commit 55a733a

File tree

5 files changed

+63
-29
lines changed

5 files changed

+63
-29
lines changed

src/pam/converse.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::ffi::{c_int, c_void};
22
use std::time::Duration;
33

44
use crate::cutils::string_from_ptr;
5+
use crate::gettext::xlat;
56
use crate::pam::rpassword::Hidden;
67
use crate::system::signal::{self, SignalSet};
78

@@ -144,8 +145,9 @@ impl CLIConverser {
144145
impl Converser for CLIConverser {
145146
fn handle_normal_prompt(&self, msg: &str) -> PamResult<PamBuffer> {
146147
let (mut tty, _guard) = self.open()?;
148+
let input_needed = xlat!("input needed");
147149
tty.read_input(
148-
&format!("[{}: input needed] {msg} ", self.name),
150+
&format!("[{}: {input_needed} {msg} ", self.name),
149151
None,
150152
Hidden::No,
151153
)

src/pam/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{
77
time::Duration,
88
};
99

10+
use crate::gettext::xlat;
1011
use crate::system::signal::{self, SignalSet};
1112

1213
use converse::ConverserData;
@@ -80,7 +81,7 @@ impl PamContext {
8081
converser,
8182
converser_name: converser_name.to_owned(),
8283
no_interact,
83-
auth_prompt: Some("authenticate".to_owned()),
84+
auth_prompt: Some(xlat!("authenticate").to_owned()),
8485
error: None,
8586
panicked: false,
8687
}));

src/sudo/cli/mod.rs

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,11 @@ impl TryFrom<SudoOptions> for SudoValidateOptions {
207207
let user = mem::take(&mut opts.user);
208208

209209
if bell && stdin {
210-
return Err("--bell conflicts with --stdin".into());
210+
return Err(xlat!(
211+
"{option1} conflicts with {option2}",
212+
option1 = "--bell",
213+
option2 = "--stdin"
214+
));
211215
}
212216

213217
reject_all("--validate", opts)?;
@@ -268,13 +272,17 @@ impl TryFrom<SudoOptions> for SudoEditOptions {
268272
let positional_args = mem::take(&mut opts.positional_args);
269273

270274
if bell && stdin {
271-
return Err("--bell conflicts with --stdin".into());
275+
return Err(xlat!(
276+
"{option1} conflicts with {option2}",
277+
option1 = "--bell",
278+
option2 = "--stdin"
279+
));
272280
}
273281

274282
reject_all("--edit", opts)?;
275283

276284
if positional_args.is_empty() {
277-
return Err("must specify at least one file path".into());
285+
return Err(xlat!("must specify at least one file path").into());
278286
}
279287

280288
Ok(Self {
@@ -336,15 +344,22 @@ impl TryFrom<SudoOptions> for SudoListOptions {
336344
let positional_args = mem::take(&mut opts.positional_args);
337345

338346
if bell && stdin {
339-
return Err("--bell conflicts with --stdin".into());
347+
return Err(xlat!(
348+
"{option1} conflicts with {option2}",
349+
option1 = "--bell",
350+
option2 = "--stdin"
351+
));
340352
}
341353

342354
// when present, `-u` must be accompanied by a command
343355
let has_command = !positional_args.is_empty();
344356
let valid_user_flag = user.is_none() || has_command;
345357

346358
if !valid_user_flag {
347-
return Err("'--user' flag must be accompanied by a command".into());
359+
return Err(xlat!(
360+
"'{option}' flag must be accompanied by a command",
361+
option = "--user"
362+
));
348363
}
349364

350365
reject_all("--list", opts)?;
@@ -415,24 +430,34 @@ impl TryFrom<SudoOptions> for SudoRunOptions {
415430
let positional_args = mem::take(&mut opts.positional_args);
416431

417432
if bell && stdin {
418-
return Err("--bell conflicts with --stdin".into());
433+
return Err(xlat!(
434+
"{option1} conflicts with {option2}",
435+
option1 = "--bell",
436+
option2 = "--stdin"
437+
));
419438
}
420439

421440
let context = match (login, shell, positional_args.is_empty()) {
422441
(true, false, _) => "--login",
423442
(false, true, _) => "--shell",
424-
(false, false, false) => "command (positional argument)",
425-
426-
(true, true, _) => return Err("--login conflicts with --shell".into()),
443+
(false, false, false) => xlat!("command (positional argument)"),
444+
445+
(true, true, _) => {
446+
return Err(xlat!(
447+
"{option1} conflicts with {option2}",
448+
option1 = "--login",
449+
option2 = "--shell"
450+
))
451+
}
427452
(false, false, true) => {
428453
if cfg!(debug_assertions) {
429454
// see `SudoOptions::validate`
430455
panic!();
431456
} else {
432-
return Err(
457+
return Err(xlat!(
433458
"expected one of: --login, --shell, a command as a positional argument"
434-
.into(),
435-
);
459+
)
460+
.into());
436461
}
437462
}
438463
};
@@ -586,7 +611,7 @@ impl SudoArg {
586611

587612
// assignment syntax is not accepted for shorthand arguments
588613
if next == Some('=') {
589-
Err("invalid option '='")?;
614+
Err(xlat!("invalid option '='"))?;
590615
}
591616
if next.is_some() {
592617
processed.push(SudoArg::Argument(flag, rest.to_string()));
@@ -596,7 +621,7 @@ impl SudoArg {
596621
// short version of --help has no arguments
597622
processed.push(SudoArg::Flag(flag));
598623
} else {
599-
Err(xlat!("'-{option}' expects an argument", option = curr))?;
624+
Err(xlat!("'{option}' expects an argument", option = flag))?;
600625
}
601626
break;
602627
} else {
@@ -639,7 +664,7 @@ impl SudoOptions {
639664
} else if self.reset_timestamp {
640665
SudoAction::ResetTimestamp(self.try_into()?)
641666
} else {
642-
return Err("expected one of these actions: --help, --version, --remove-timestamp, --validate, --list, --edit, --login, --shell, a command as a positional argument, --reset-timestamp".into());
667+
return Err(xlat!("expected one of these actions: --help, --version, --remove-timestamp, --validate, --list, --edit, --login, --shell, a command as a positional argument, --reset-timestamp").into());
643668
}
644669
};
645670

@@ -720,7 +745,7 @@ impl SudoOptions {
720745
options.validate = true;
721746
}
722747
_option => {
723-
Err("invalid option provided")?;
748+
Err(xlat!("invalid option provided"))?;
724749
}
725750
},
726751
SudoArg::Argument(option, value) => match option.as_str() {
@@ -749,7 +774,7 @@ impl SudoOptions {
749774
options.user = Some(SudoString::from_cli_string(value));
750775
}
751776
_option => {
752-
Err("invalid option provided")?;
777+
Err(xlat!("invalid option provided"))?;
753778
}
754779
},
755780
SudoArg::Environment(key, value) => {
@@ -828,7 +853,7 @@ fn ensure_is_absent(context: &str, thing: &dyn IsAbsent, name: &str) -> Result<(
828853

829854
fn reject_all(context: &str, opts: SudoOptions) -> Result<(), String> {
830855
macro_rules! check_options {
831-
($($field:ident $(= $name:literal)?,)*) => {{
856+
($($field:ident $(= $name:expr)?,)*) => {{
832857
let SudoOptions { $($field),* } = opts;
833858

834859
$(
@@ -846,7 +871,7 @@ fn reject_all(context: &str, opts: SudoOptions) -> Result<(), String> {
846871
Cow::Borrowed(name)
847872
}
848873
}};
849-
(@name $field:ident $name:literal) => {
874+
(@name $field:ident $name:expr) => {
850875
$name
851876
};
852877
}
@@ -870,7 +895,7 @@ fn reject_all(context: &str, opts: SudoOptions) -> Result<(), String> {
870895
user,
871896
validate,
872897
version,
873-
positional_args = "command",
874-
env_var_list = "environment variable",
898+
positional_args = xlat!("command"),
899+
env_var_list = xlat!("environment variable"),
875900
)
876901
}

src/sudo/edit.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,18 @@ fn handle_child_inner(editor: &Path, mut files: Vec<ChildFileInfo<'_>>) -> Resul
299299

300300
// If the file has been changed to be empty, ask the user what to do.
301301
if new_data.is_empty() && new_data != file.old_data {
302+
// TRANSLATORS: the initial letters of 'yes' and 'no' responses, in that order
303+
let answers = xlat!("yn").as_bytes().get(..2).unwrap_or(b"yn");
304+
302305
match crate::visudo::ask_response(
303306
xlat!(
304307
"sudoedit: truncate {path} to zero? (y/n) [n] ",
305308
path = file.path.display()
306309
)
307310
.as_bytes(),
308-
b"yn",
311+
answers,
309312
) {
310-
Ok(b'y') => {}
313+
Ok(val) if val == answers[0] => {}
311314
_ => {
312315
user_info!("not overwriting {path}", path = file.path.display());
313316

src/system/audit.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,17 @@ fn traversed_secure_open(path: impl AsRef<Path>, forbidden_user: &User) -> io::R
248248
let path = path.as_ref();
249249

250250
let Some(file_name) = path.file_name() else {
251-
return Err(io::Error::new(ErrorKind::InvalidInput, "invalid path"));
251+
return Err(io::Error::new(
252+
ErrorKind::InvalidInput,
253+
xlat!("invalid path"),
254+
));
252255
};
253256

254257
let mut components = path.parent().unwrap_or(Path::new("")).components();
255258
if components.next() != Some(Component::RootDir) {
256259
return Err(io::Error::new(
257260
ErrorKind::InvalidInput,
258-
"path must be absolute",
261+
xlat!("path must be absolute"),
259262
));
260263
}
261264

@@ -271,7 +274,7 @@ fn traversed_secure_open(path: impl AsRef<Path>, forbidden_user: &User) -> io::R
271274
{
272275
Err(io::Error::new(
273276
ErrorKind::PermissionDenied,
274-
"cannot open a file in a path writable by the user",
277+
xlat!("cannot open a file in a path writable by the user"),
275278
))
276279
} else {
277280
Ok(())
@@ -289,7 +292,7 @@ fn traversed_secure_open(path: impl AsRef<Path>, forbidden_user: &User) -> io::R
289292
_ => {
290293
return Err(io::Error::new(
291294
ErrorKind::InvalidInput,
292-
"error in provided path",
295+
xlat!("error in provided path"),
293296
))
294297
}
295298
};

0 commit comments

Comments
 (0)