From bd6f1cfbe5dba0274104d38c5e0a8fdcf55157e8 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 8 Jun 2025 19:35:03 +0200 Subject: [PATCH] l10n: port timeout for translation + add french --- src/uu/timeout/locales/en-US.ftl | 14 +++++++++ src/uu/timeout/locales/fr-FR.ftl | 16 ++++++++++ src/uu/timeout/src/timeout.rs | 52 ++++++++++++++++++++------------ 3 files changed, 62 insertions(+), 20 deletions(-) create mode 100644 src/uu/timeout/locales/fr-FR.ftl diff --git a/src/uu/timeout/locales/en-US.ftl b/src/uu/timeout/locales/en-US.ftl index 57126de1e..1c5f20ef7 100644 --- a/src/uu/timeout/locales/en-US.ftl +++ b/src/uu/timeout/locales/en-US.ftl @@ -1,2 +1,16 @@ timeout-about = Start COMMAND, and kill it if still running after DURATION. timeout-usage = timeout [OPTION] DURATION COMMAND... + +# Help messages +timeout-help-foreground = when not running timeout directly from a shell prompt, allow COMMAND to read from the TTY and get TTY signals; in this mode, children of COMMAND will not be timed out +timeout-help-kill-after = also send a KILL signal if COMMAND is still running this long after the initial signal was sent +timeout-help-preserve-status = exit with the same status as COMMAND, even when the command times out +timeout-help-signal = specify the signal to be sent on timeout; SIGNAL may be a name like 'HUP' or a number; see 'kill -l' for a list of signals +timeout-help-verbose = diagnose to stderr any signal sent upon timeout + +# Error messages +timeout-error-invalid-signal = { $signal }: invalid signal +timeout-error-failed-to-execute-process = failed to execute process: { $error } + +# Verbose messages +timeout-verbose-sending-signal = sending signal { $signal } to command { $command } diff --git a/src/uu/timeout/locales/fr-FR.ftl b/src/uu/timeout/locales/fr-FR.ftl new file mode 100644 index 000000000..d8e09e6a2 --- /dev/null +++ b/src/uu/timeout/locales/fr-FR.ftl @@ -0,0 +1,16 @@ +timeout-about = Démarrer COMMANDE, et la tuer si elle fonctionne encore après DURÉE. +timeout-usage = timeout [OPTION] DURÉE COMMANDE... + +# Messages d'aide +timeout-help-foreground = quand on n'exécute pas timeout directement depuis une invite de shell, permettre à COMMANDE de lire depuis le TTY et d'obtenir les signaux TTY ; dans ce mode, les enfants de COMMANDE ne seront pas limités dans le temps +timeout-help-kill-after = envoyer aussi un signal KILL si COMMANDE fonctionne encore si longtemps après que le signal initial ait été envoyé +timeout-help-preserve-status = sortir avec le même statut que COMMANDE, même quand la commande dépasse le délai +timeout-help-signal = spécifier le signal à envoyer en cas de délai dépassé ; SIGNAL peut être un nom comme 'HUP' ou un nombre ; voir 'kill -l' pour une liste des signaux +timeout-help-verbose = diagnostiquer vers stderr tout signal envoyé lors d'un dépassement de délai + +# Messages d'erreur +timeout-error-invalid-signal = { $signal } : signal invalide +timeout-error-failed-to-execute-process = échec d'exécution du processus : { $error } + +# Messages détaillés +timeout-verbose-sending-signal = envoi du signal { $signal } à la commande { $command } diff --git a/src/uu/timeout/src/timeout.rs b/src/uu/timeout/src/timeout.rs index 35232d3e4..50d5afcfb 100644 --- a/src/uu/timeout/src/timeout.rs +++ b/src/uu/timeout/src/timeout.rs @@ -8,6 +8,7 @@ mod status; use crate::status::ExitStatus; use clap::{Arg, ArgAction, Command}; +use std::collections::HashMap; use std::io::ErrorKind; use std::os::unix::process::ExitStatusExt; use std::process::{self, Child, Stdio}; @@ -17,7 +18,7 @@ use uucore::error::{UClapError, UResult, USimpleError, UUsageError}; use uucore::parser::parse_time; use uucore::process::ChildExt; -use uucore::locale::get_message; +use uucore::locale::{get_message, get_message_with_args}; #[cfg(unix)] use uucore::signals::enable_pipe_errors; @@ -58,7 +59,13 @@ impl Config { None => { return Err(UUsageError::new( ExitStatus::TimeoutFailed.into(), - format!("{}: invalid signal", signal_.quote()), + get_message_with_args( + "timeout-error-invalid-signal", + HashMap::from([( + "signal".to_string(), + signal_.quote().to_string(), + )]), + ), )); } Some(signal_value) => signal_value, @@ -126,44 +133,34 @@ pub fn uu_app() -> Command { Arg::new(options::FOREGROUND) .long(options::FOREGROUND) .short('f') - .help( - "when not running timeout directly from a shell prompt, allow \ - COMMAND to read from the TTY and get TTY signals; in this mode, \ - children of COMMAND will not be timed out", - ) + .help(get_message("timeout-help-foreground")) .action(ArgAction::SetTrue), ) .arg( Arg::new(options::KILL_AFTER) .long(options::KILL_AFTER) .short('k') - .help( - "also send a KILL signal if COMMAND is still running this long \ - after the initial signal was sent", - ), + .help(get_message("timeout-help-kill-after")), ) .arg( Arg::new(options::PRESERVE_STATUS) .long(options::PRESERVE_STATUS) .short('p') - .help("exit with the same status as COMMAND, even when the command times out") + .help(get_message("timeout-help-preserve-status")) .action(ArgAction::SetTrue), ) .arg( Arg::new(options::SIGNAL) .short('s') .long(options::SIGNAL) - .help( - "specify the signal to be sent on timeout; SIGNAL may be a name like \ - 'HUP' or a number; see 'kill -l' for a list of signals", - ) + .help(get_message("timeout-help-signal")) .value_name("SIGNAL"), ) .arg( Arg::new(options::VERBOSE) .short('v') .long(options::VERBOSE) - .help("diagnose to stderr any signal sent upon timeout") + .help(get_message("timeout-help-verbose")) .action(ArgAction::SetTrue), ) .arg(Arg::new(options::DURATION).required(true)) @@ -192,7 +189,16 @@ fn unblock_sigchld() { fn report_if_verbose(signal: usize, cmd: &str, verbose: bool) { if verbose { let s = signal_name_by_value(signal).unwrap(); - show_error!("sending signal {s} to command {}", cmd.quote()); + show_error!( + "{}", + get_message_with_args( + "timeout-verbose-sending-signal", + HashMap::from([ + ("signal".to_string(), s.to_string()), + ("command".to_string(), cmd.quote().to_string()) + ]) + ) + ); } } @@ -315,7 +321,13 @@ fn timeout( // FIXME: this may not be 100% correct... 126 }; - USimpleError::new(status_code, format!("failed to execute process: {err}")) + USimpleError::new( + status_code, + get_message_with_args( + "timeout-error-failed-to-execute-process", + HashMap::from([("error".to_string(), err.to_string())]), + ), + ) })?; unblock_sigchld(); // Wait for the child process for the specified time period. @@ -364,7 +376,7 @@ fn timeout( Ok(status) => Err(status.into()), Err(e) => Err(USimpleError::new( ExitStatus::TimeoutFailed.into(), - format!("{e}"), + e.to_string(), )), } }