From 417eece650df10f84bc07f41e0d9ce088474478c Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 14 Jun 2025 22:54:18 +0200 Subject: [PATCH] l10n: port mkfifo for translation + add french --- src/uu/mkfifo/locales/en-US.ftl | 11 +++++++++ src/uu/mkfifo/locales/fr-FR.ftl | 13 ++++++++++ src/uu/mkfifo/src/mkfifo.rs | 43 ++++++++++++++++++++++++--------- 3 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 src/uu/mkfifo/locales/fr-FR.ftl diff --git a/src/uu/mkfifo/locales/en-US.ftl b/src/uu/mkfifo/locales/en-US.ftl index aee4bba92..2a02e7d0d 100644 --- a/src/uu/mkfifo/locales/en-US.ftl +++ b/src/uu/mkfifo/locales/en-US.ftl @@ -1,2 +1,13 @@ mkfifo-about = Create a FIFO with the given name. mkfifo-usage = mkfifo [OPTION]... NAME... + +# Help messages +mkfifo-help-mode = file permissions for the fifo +mkfifo-help-selinux = set the SELinux security context to default type +mkfifo-help-context = like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX + +# Error messages +mkfifo-error-invalid-mode = invalid mode: { $error } +mkfifo-error-missing-operand = missing operand +mkfifo-error-cannot-create-fifo = cannot create fifo { $path }: File exists +mkfifo-error-cannot-set-permissions = cannot set permissions on { $path }: { $error } diff --git a/src/uu/mkfifo/locales/fr-FR.ftl b/src/uu/mkfifo/locales/fr-FR.ftl new file mode 100644 index 000000000..d47722463 --- /dev/null +++ b/src/uu/mkfifo/locales/fr-FR.ftl @@ -0,0 +1,13 @@ +mkfifo-about = Créer un FIFO avec le nom donné. +mkfifo-usage = mkfifo [OPTION]... NOM... + +# Messages d'aide +mkfifo-help-mode = permissions de fichier pour le fifo +mkfifo-help-selinux = définir le contexte de sécurité SELinux au type par défaut +mkfifo-help-context = comme -Z, ou si CTX est spécifié, définir le contexte de sécurité SELinux ou SMACK à CTX + +# Messages d'erreur +mkfifo-error-invalid-mode = mode invalide : { $error } +mkfifo-error-missing-operand = opérande manquant +mkfifo-error-cannot-create-fifo = impossible de créer le fifo { $path } : Le fichier existe +mkfifo-error-cannot-set-permissions = impossible de définir les permissions sur { $path } : { $error } diff --git a/src/uu/mkfifo/src/mkfifo.rs b/src/uu/mkfifo/src/mkfifo.rs index ea5880438..3e6ea11ba 100644 --- a/src/uu/mkfifo/src/mkfifo.rs +++ b/src/uu/mkfifo/src/mkfifo.rs @@ -5,15 +5,15 @@ use clap::{Arg, ArgAction, Command, value_parser}; use libc::mkfifo; +use std::collections::HashMap; use std::ffi::CString; use std::fs; use std::os::unix::fs::PermissionsExt; use uucore::display::Quotable; use uucore::error::{UResult, USimpleError}; +use uucore::locale::{get_message, get_message_with_args}; use uucore::{format_usage, show}; -use uucore::locale::get_message; - mod options { pub static MODE: &str = "mode"; pub static SELINUX: &str = "Z"; @@ -29,7 +29,15 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // if mode is passed, ignore umask Some(m) => match usize::from_str_radix(m, 8) { Ok(m) => m, - Err(e) => return Err(USimpleError::new(1, format!("invalid mode: {e}"))), + Err(e) => { + return Err(USimpleError::new( + 1, + get_message_with_args( + "mkfifo-error-invalid-mode", + HashMap::from([("error".to_string(), e.to_string())]), + ), + )); + } }, // Default value + umask if present None => 0o666 & !(uucore::mode::get_umask() as usize), @@ -37,7 +45,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let fifos: Vec = match matches.get_many::(options::FIFO) { Some(v) => v.cloned().collect(), - None => return Err(USimpleError::new(1, "missing operand")), + None => { + return Err(USimpleError::new( + 1, + get_message("mkfifo-error-missing-operand"), + )); + } }; for f in fifos { @@ -48,7 +61,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if err == -1 { show!(USimpleError::new( 1, - format!("cannot create fifo {}: File exists", f.quote()), + get_message_with_args( + "mkfifo-error-cannot-create-fifo", + HashMap::from([("path".to_string(), f.quote().to_string())]), + ), )); } @@ -56,7 +72,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if let Err(e) = fs::set_permissions(&f, fs::Permissions::from_mode(mode as u32)) { return Err(USimpleError::new( 1, - format!("cannot set permissions on {}: {e}", f.quote()), + get_message_with_args( + "mkfifo-error-cannot-set-permissions", + HashMap::from([ + ("path".to_string(), f.quote().to_string()), + ("error".to_string(), e.to_string()), + ]), + ), )); } @@ -92,13 +114,13 @@ pub fn uu_app() -> Command { Arg::new(options::MODE) .short('m') .long(options::MODE) - .help("file permissions for the fifo") + .help(get_message("mkfifo-help-mode")) .value_name("MODE"), ) .arg( Arg::new(options::SELINUX) .short('Z') - .help("set the SELinux security context to default type") + .help(get_message("mkfifo-help-selinux")) .action(ArgAction::SetTrue), ) .arg( @@ -108,10 +130,7 @@ pub fn uu_app() -> Command { .value_parser(value_parser!(String)) .num_args(0..=1) .require_equals(true) - .help( - "like -Z, or if CTX is specified then set the SELinux \ - or SMACK security context to CTX", - ), + .help(get_message("mkfifo-help-context")), ) .arg( Arg::new(options::FIFO)