Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/uu/yes/locales/en-US.ftl
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
yes-about = Repeatedly display a line with STRING (or 'y')
yes-usage = yes [STRING]...

# Error messages
yes-error-standard-output = standard output: { $error }
yes-error-invalid-utf8 = arguments contain invalid UTF-8
6 changes: 6 additions & 0 deletions src/uu/yes/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
yes-about = Affiche de façon répétée une ligne avec CHAÎNE (ou 'y')
yes-usage = yes [CHAÎNE]...

# Messages d'erreur
yes-error-standard-output = sortie standard : { $error }
yes-error-invalid-utf8 = les arguments contiennent de l'UTF-8 invalide
13 changes: 10 additions & 3 deletions src/uu/yes/src/yes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// cSpell:ignore strs

use clap::{Arg, ArgAction, Command, builder::ValueParser};
use std::collections::HashMap;
use std::error::Error;
use std::ffi::OsString;
use std::io::{self, Write};
Expand All @@ -14,7 +15,7 @@ use uucore::format_usage;
#[cfg(unix)]
use uucore::signals::enable_pipe_errors;

use uucore::locale::get_message;
use uucore::locale::{get_message, get_message_with_args};

// it's possible that using a smaller or larger buffer might provide better performance on some
// systems, but honestly this is good enough
Expand All @@ -31,7 +32,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
match exec(&buffer) {
Ok(()) => Ok(()),
Err(err) if err.kind() == io::ErrorKind::BrokenPipe => Ok(()),
Err(err) => Err(USimpleError::new(1, format!("standard output: {err}"))),
Err(err) => Err(USimpleError::new(
1,
get_message_with_args(
"yes-error-standard-output",
HashMap::from([("error".to_string(), err.to_string())]),
),
)),
}
}

Expand Down Expand Up @@ -77,7 +84,7 @@ fn args_into_buffer<'a>(
for part in itertools::intersperse(i.map(|a| a.to_str()), Some(" ")) {
let bytes = match part {
Some(part) => part.as_bytes(),
None => return Err("arguments contain invalid UTF-8".into()),
None => return Err(get_message("yes-error-invalid-utf8").into()),
};
buf.extend_from_slice(bytes);
}
Expand Down
Loading