8000 l10n: port head for translation + add french by sylvestre · Pull Request #8240 · uutils/coreutils · GitHub
[go: up one dir, main page]

Skip to content

l10n: port head for translation + add french #8240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2025
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
26 changes: 26 additions & 0 deletions src/uu/head/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,29 @@ head-about = Print the first 10 lines of each FILE to standard output.

Mandatory arguments to long flags are mandatory for short flags too.
head-usage = head [FLAG]... [FILE]...

# Help messages
head-help-bytes = print the first NUM bytes of each file;
with the leading '-', print all but the last
NUM bytes of each file
head-help-lines = print the first NUM lines instead of the first 10;
with the leading '-', print all but the last
NUM lines of each file
head-help-quiet = never print headers giving file names
head-help-verbose = always print headers giving file names
head-help-zero-terminated = line delimiter is NUL, not newline

# Error messages
head-error-reading-file = error reading {$name}: {$err}
head-error-parse-error = parse error: {$err}
head-error-bad-encoding = bad argument encoding
head-error-num-too-large = number of -bytes or -lines is too large
head-error-clap = clap error: {$err}
head-error-invalid-bytes = invalid number of bytes: {$err}
head-error-invalid-lines = invalid number of lines: {$err}
head-error-bad-argument-format = bad argument format: {$arg}
head-error-writing-stdout = error writing 'standard output': {$err}
head-error-cannot-open = cannot open {$name} for reading

# Output headers
head-header-stdin = ==> standard input <==
32 changes: 32 additions & 0 deletions src/uu/head/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
head-about = Affiche les 10 premières lignes de chaque FICHIER sur la sortie standard.
Avec plus d'un FICHIER, précède chacun d'un en-tête donnant le nom du fichier.
Sans FICHIER, ou quand FICHIER est -, lit l'entrée standard.

Les arguments obligatoires pour les drapeaux longs sont obligatoires pour les drapeaux courts aussi.
head-usage = head [DRAPEAU]... [FICHIER]...

# Messages d'aide
head-help-bytes = affiche les premiers NUM octets de chaque fichier ;
avec le préfixe '-', affiche tout sauf les derniers
NUM octets de chaque fichier
head-help-lines = affiche les premières NUM lignes au lieu des 10 premières ;
avec le préfixe '-', affiche tout sauf les dernières
NUM lignes de chaque fichier
head-help-quiet = n'affiche jamais les en-têtes donnant les noms de fichiers
head-help-verbose = affiche toujours les en-têtes donnant les noms de fichiers
head-help-zero-terminated = le délimiteur de ligne est NUL, pas nouvelle ligne

# Messages d'erreur
head-error-reading-file = erreur lors de la lecture de {$name} : {$err}
head-error-parse-error = erreur d'analyse : {$err}
head-error-bad-encoding = mauvais encodage d'argument
head-error-num-too-large = le nombre d'octets ou de lignes est trop grand
head-error-clap = erreur clap : {$err}
head-error-invalid-bytes = nombre d'octets invalide : {$err}
head-error-invalid-lines = nombre de lignes invalide : {$err}
head-error-bad-argument-format = format d'argument incorrect : {$arg}
head-error-writing-stdout = erreur lors de l'écriture sur 'sortie standard' : {$err}
head-error-cannot-open = impossible d'ouvrir {$name} en lecture

# En-têtes de sortie
head-header-stdin = ==> entrée standard <==
70 changes: 35 additions & 35 deletions src/uu/head/src/head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,28 @@

mod parse;
mod take;
use std::collections::HashMap;
use take::copy_all_but_n_bytes;
use take::copy_all_but_n_lines;
use take::take_lines;
use uucore::locale::get_message;
use uucore::locale::{get_message, get_message_with_args};

#[derive(Error, Debug)]
enum HeadError {
/// Wrapper around `io::Error`
#[error("error reading {name}: {err}")]
#[error("{}", get_message_with_args("head-error-reading-file", HashMap::from([("name".to_string(), name.clone()), ("err".to_string(), err.to_string())])))]
Io { name: String, err: io::Error },

#[error("parse error: {0}")]
#[error("{}", get_message_with_args("head-error-parse-error", HashMap::from([("err".to_string(), 0.to_string())])))]
ParseError(String),

#[error("bad argument encoding")]
#[error("{}", get_message("head-error-bad-encoding"))]
BadEncoding,

#[error("{0}: number of -bytes or -lines is too large")]
#[error("{}", get_message("head-error-num-too-large"))]
NumTooLarge(#[from] TryFromIntError),

#[error("clap error: {0}")]
#[error("{}", get_message_with_args("head-error-clap", HashMap::from([("err".to_string(), 0.to_string())])))]
Clap(#[from] clap::Error),

#[error("{0}")]
Expand All @@ -79,13 +80,7 @@
.short('c')
.long("bytes")
.value_name("[-]NUM")
.help(
"\
print the first NUM bytes of each file;\n\
with the leading '-', print all but the last\n\
NUM bytes of each file\
",
)
.help(get_message("head-help-bytes"))
.overrides_with_all([options::BYTES_NAME, options::LINES_NAME])
.allow_hyphen_values(true),
)
Expand All @@ -94,13 +89,7 @@
.short('n')
.long("lines")
.value_name("[-]NUM")
.help(
"\
print the first NUM lines instead of the first 10;\n\
with the leading '-', print all but the last\n\
NUM lines of each file\
",
)
.help(get_message("head-help-lines"))
.overrides_with_all([options::LINES_NAME, options::BYTES_NAME])
.allow_hyphen_values(true),
)
Expand All @@ -109,15 +98,15 @@
.short('q')
.long("quiet")
.visible_alias("silent")
.help("never print headers giving file names")
.help(get_message("head-help-quiet"))
.overrides_with_all([options::VERBOSE_NAME, options::QUIET_NAME])
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::VERBOSE_NAME)
.short('v')
.long("verbose")
.help("always print headers giving file names")
.help(get_message("head-help-verbose"))
.overrides_with_all([options::QUIET_NAME, options::VERBOSE_NAME])
.action(ArgAction::SetTrue),
)
Expand All @@ -132,7 +121,7 @@
Arg::new(options::ZERO_NAME)
.short('z')
.long("zero-terminated")
.help("line delimiter is NUL, not newline")
.help(get_message("head-help-zero-terminated"))
.overrides_with(options::ZERO_NAME)
.action(ArgAction::SetTrue),
)
Expand Down Expand Up @@ -160,16 +149,24 @@
impl Mode {
fn from(matches: &ArgMatches) -> Result<Self, String> {
if let Some(v) = matches.get_one::<String>(options::BYTES_NAME) {
let (n, all_but_last) =
parse::parse_num(v).map_err(|err| format!("invalid number of bytes: {err}"))?;
let (n, all_but_last) = parse::parse_num(v).map_err(|err| {
get_message_with_args(
"head-error-invalid-bytes",
HashMap::from([("err".to_string(), err.to_string())]),
)
})?;
if all_but_last {
Ok(Self::AllButLastBytes(n))
} else {
Ok(Self::FirstBytes(n))
}
} else if let Some(v) = matches.get_one::<String>(options::LINES_NAME) {
let (n, all_but_last) =
parse::parse_num(v).map_err(|err| format!("invalid number of lines: {err}"))?;
let (n, all_but_last) = parse::parse_num(v).map_err(|err| {
get_message_with_args(
"head-error-invalid-lines",
HashMap::from([("err".to_string(), err.to_string())]),

Check warning on line 167 in src/uu/head/src/head.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/head/src/head.rs#L165-L167

Added lines #L165 - L167 were not covered by tests
)
})?;

Check warning on line 169 in src/uu/head/src/head.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/head/src/head.rs#L169

Added line #L169 was not covered by tests
if all_but_last {
Ok(Self::AllButLastLines(n))
} else {
Expand All @@ -190,9 +187,9 @@
if let Some(s) = second.to_str() {
match parse::parse_obsolete(s) {
Some(Ok(iter)) => Ok(Box::new(vec![first].into_iter().chain(iter).chain(args))),
Some(Err(parse::ParseError)) => Err(HeadError::ParseError(format!(
"bad argument format: {}",
s.quote()
Some(Err(parse::ParseError)) => Err(HeadError::ParseError(get_message_with_args(
"head-error-bad-argument-format",
HashMap::from([("arg".to_string(), s.quote().to_string())]),

Check warning on line 192 in src/uu/head/src/head.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/head/src/head.rs#L190-L192

Added lines #L190 - L192 were not covered by tests
))),
None => Ok(Box::new(vec![first, second].into_iter().chain(args))),
}
Expand Down Expand Up @@ -239,7 +236,10 @@
fn wrap_in_stdout_error(err: io::Error) -> io::Error {
io::Error::new(
err.kind(),
format!("error writing 'standard output': {err}"),
get_message_with_args(
"head-error-writing-stdout",
HashMap::from([("err".to_string(), err.to_string())]),
),
)
}

Expand Down Expand Up @@ -480,7 +480,7 @@
if !first {
println!();
}
println!("==> standard input <==");
println!("{}", get_message("head-header-stdin"));
}
let stdin = io::stdin();

Expand Down Expand Up @@ -523,9 +523,9 @@
let mut file = match File::open(name) {
Ok(f) => f,
Err(err) => {
show!(err.map_err_context(|| format!(
"cannot open {} for reading",
name.quote()
show!(err.map_err_context(|| get_message_with_args(
"head-error-cannot-open",
HashMap::from([("name".to_string(), name.quote().to_string())])
)));
continue;
}
Expand Down
Loading
0