From 4bf4dae9f44840cb01c5c60636798f57499c7d94 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 10 Jun 2025 21:09:13 +0200 Subject: [PATCH] l10n: port kill for translation + add french --- src/uu/kill/locales/en-US.ftl | 12 +++++++++ src/uu/kill/locales/fr-FR.ftl | 14 +++++++++++ src/uu/kill/src/kill.rs | 47 ++++++++++++++++++++++++----------- 3 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 src/uu/kill/locales/fr-FR.ftl diff --git a/src/uu/kill/locales/en-US.ftl b/src/uu/kill/locales/en-US.ftl index 3038adaed..e04dd8709 100644 --- a/src/uu/kill/locales/en-US.ftl +++ b/src/uu/kill/locales/en-US.ftl @@ -1,2 +1,14 @@ kill-about = Send signal to processes or list information about signals. kill-usage = kill [OPTIONS]... PID... + +# Help messages +kill-help-list = Lists signals +kill-help-table = Lists table of signals +kill-help-signal = Sends given signal instead of SIGTERM + +# Error messages +kill-error-no-process-id = no process ID specified + Try --help for more information. +kill-error-invalid-signal = { $signal }: invalid signal +kill-error-parse-argument = failed to parse argument { $argument }: { $error } +kill-error-sending-signal = sending signal to { $pid } failed diff --git a/src/uu/kill/locales/fr-FR.ftl b/src/uu/kill/locales/fr-FR.ftl new file mode 100644 index 000000000..2b7b1067d --- /dev/null +++ b/src/uu/kill/locales/fr-FR.ftl @@ -0,0 +1,14 @@ +kill-about = Envoyer un signal aux processus ou lister les informations sur les signaux. +kill-usage = kill [OPTIONS]... PID... + +# Messages d'aide +kill-help-list = Liste les signaux +kill-help-table = Liste le tableau des signaux +kill-help-signal = Envoie le signal donné au lieu de SIGTERM + +# Messages d'erreur +kill-error-no-process-id = aucun ID de processus spécifié + Essayez --help pour plus d'informations. +kill-error-invalid-signal = { $signal } : signal invalide +kill-error-parse-argument = échec de l'analyse de l'argument { $argument } : { $error } +kill-error-sending-signal = échec de l'envoi du signal au processus { $pid } diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index 6c67aede9..4529f35d8 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -8,14 +8,14 @@ use clap::{Arg, ArgAction, Command}; use nix::sys::signal::{self, Signal}; use nix::unistd::Pid; +use std::collections::HashMap; use std::io::Error; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError}; +use uucore::locale::{get_message, get_message_with_args}; use uucore::signals::{ALL_SIGNALS, signal_by_name_or_value, signal_name_by_value}; use uucore::{format_usage, show}; -use uucore::locale::get_message; - // When the -l option is selected, the program displays the type of signal related to a certain // value or string. In case of a value, the program should control the lower 8 bits, but there is // a particular case in which if the value is in range [128, 159], it is translated to a signal @@ -81,8 +81,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if pids.is_empty() { Err(USimpleError::new( 1, - "no process ID specified\n\ - Try --help for more information.", + get_message("kill-error-no-process-id"), )) } else { kill(sig, &pids); @@ -111,7 +110,7 @@ pub fn uu_app() -> Command { Arg::new(options::LIST) .short('l') .long(options::LIST) - .help("Lists signals") + .help(get_message("kill-help-list")) .conflicts_with(options::TABLE) .action(ArgAction::SetTrue), ) @@ -120,7 +119,7 @@ pub fn uu_app() -> Command { .short('t') .short_alias('L') .long(options::TABLE) - .help("Lists table of signals") + .help(get_message("kill-help-table")) .action(ArgAction::SetTrue), ) .arg( @@ -129,7 +128,7 @@ pub fn uu_app() -> Command { .short_alias('n') // For bash compatibility, like in GNU coreutils .long(options::SIGNAL) .value_name("signal") - .help("Sends given signal instead of SIGTERM") + .help(get_message("kill-help-signal")) .conflicts_with_all([options::LIST, options::TABLE]), ) .arg( @@ -192,7 +191,13 @@ fn print_signal(signal_name_or_value: &str) -> UResult<()> { } Err(USimpleError::new( 1, - format!("{}: invalid signal", signal_name_or_value.quote()), + get_message_with_args( + "kill-error-invalid-signal", + HashMap::from([( + "signal".to_string(), + signal_name_or_value.quote().to_string(), + )]), + ), )) } @@ -220,7 +225,10 @@ fn parse_signal_value(signal_name: &str) -> UResult { Some(x) => Ok(x), None => Err(USimpleError::new( 1, - format!("{}: invalid signal", signal_name.quote()), + get_message_with_args( + "kill-error-invalid-signal", + HashMap::from([("signal".to_string(), signal_name.quote().to_string())]), + ), )), } } @@ -229,7 +237,16 @@ fn parse_pids(pids: &[String]) -> UResult> { pids.iter() .map(|x| { x.parse::().map_err(|e| { - USimpleError::new(1, format!("failed to parse argument {}: {e}", x.quote())) + USimpleError::new( + 1, + get_message_with_args( + "kill-error-parse-argument", + HashMap::from([ + ("argument".to_string(), x.quote().to_string()), + ("error".to_string(), e.to_string()), + ]), + ), + ) }) }) .collect() @@ -238,10 +255,12 @@ fn parse_pids(pids: &[String]) -> UResult> { fn kill(sig: Option, pids: &[i32]) { for &pid in pids { if let Err(e) = signal::kill(Pid::from_raw(pid), sig) { - show!( - Error::from_raw_os_error(e as i32) - .map_err_context(|| format!("sending signal to {pid} failed")) - ); + show!(Error::from_raw_os_error(e as i32).map_err_context(|| { + get_message_with_args( + "kill-error-sending-signal", + HashMap::from([("pid".to_string(), pid.to_string())]), + ) + })); } } }