From 0b0e42340c02e629bff6fb38eeeea6dea1d0cc89 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 8 Jun 2025 20:15:03 +0200 Subject: [PATCH] l10n: port sum for translation + add french --- src/uu/sum/locales/en-US.ftl | 8 ++++++++ src/uu/sum/locales/fr-FR.ftl | 12 ++++++++++++ src/uu/sum/src/sum.rs | 18 ++++++++++++------ 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 src/uu/sum/locales/fr-FR.ftl diff --git a/src/uu/sum/locales/en-US.ftl b/src/uu/sum/locales/en-US.ftl index 0d3f34b65..832c0eaec 100644 --- a/src/uu/sum/locales/en-US.ftl +++ b/src/uu/sum/locales/en-US.ftl @@ -2,3 +2,11 @@ sum-about = Checksum and count the blocks in a file. With no FILE, or when FILE is -, read standard input. sum-usage = sum [OPTION]... [FILE]... + +# Help messages +sum-help-bsd-compatible = use the BSD sum algorithm, use 1K blocks (default) +sum-help-sysv-compatible = use System V sum algorithm, use 512 bytes blocks + +# Error messages +sum-error-is-directory = { $name }: Is a directory +sum-error-no-such-file-or-directory = { $name }: No such file or directory diff --git a/src/uu/sum/locales/fr-FR.ftl b/src/uu/sum/locales/fr-FR.ftl new file mode 100644 index 000000000..c59b62139 --- /dev/null +++ b/src/uu/sum/locales/fr-FR.ftl @@ -0,0 +1,12 @@ +sum-about = Calculer la somme de contrôle et compter les blocs dans un fichier. + + Sans FICHIER, ou quand FICHIER est -, lire l'entrée standard. +sum-usage = sum [OPTION]... [FICHIER]... + +# Messages d'aide +sum-help-bsd-compatible = utiliser l'algorithme de somme BSD, utiliser des blocs de 1K (par défaut) +sum-help-sysv-compatible = utiliser l'algorithme de somme System V, utiliser des blocs de 512 octets + +# Messages d'erreur +sum-error-is-directory = { $name } : Est un répertoire +sum-error-no-such-file-or-directory = { $name } : Aucun fichier ou répertoire de ce type diff --git a/src/uu/sum/src/sum.rs b/src/uu/sum/src/sum.rs index 0f5e6c664..41ab702e5 100644 --- a/src/uu/sum/src/sum.rs +++ b/src/uu/sum/src/sum.rs @@ -6,15 +6,15 @@ // spell-checker:ignore (ToDO) sysv use clap::{Arg, ArgAction, Command}; +use std::collections::HashMap; use std::fs::File; use std::io::{ErrorKind, Read, Write, stdin, stdout}; use std::path::Path; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError}; +use uucore::locale::{get_message, get_message_with_args}; use uucore::{format_usage, show}; -use uucore::locale::get_message; - fn bsd_sum(mut reader: impl Read) -> std::io::Result<(usize, u16)> { let mut buf = [0; 4096]; let mut bytes_read = 0; @@ -74,14 +74,20 @@ fn open(name: &str) -> UResult> { if path.is_dir() { return Err(USimpleError::new( 2, - format!("{}: Is a directory", name.maybe_quote()), + get_message_with_args( + "sum-error-is-directory", + HashMap::from([("name".to_string(), name.maybe_quote().to_string())]), + ), )); }; // Silent the warning as we want to the error message if path.metadata().is_err() { return Err(USimpleError::new( 2, - format!("{}: No such file or directory", name.maybe_quote()), + get_message_with_args( + "sum-error-no-such-file-or-directory", + HashMap::from([("name".to_string(), name.maybe_quote().to_string())]), + ), )); }; let f = File::open(path).map_err_context(String::new)?; @@ -149,14 +155,14 @@ pub fn uu_app() -> Command { .arg( Arg::new(options::BSD_COMPATIBLE) .short('r') - .help("use the BSD sum algorithm, use 1K blocks (default)") + .help(get_message("sum-help-bsd-compatible")) .action(ArgAction::SetTrue), ) .arg( Arg::new(options::SYSTEM_V_COMPATIBLE) .short('s') .long(options::SYSTEM_V_COMPATIBLE) - .help("use System V sum algorithm, use 512 bytes blocks") + .help(get_message("sum-help-sysv-compatible")) .action(ArgAction::SetTrue), ) }