diff --git a/src/uu/expand/locales/en-US.ftl b/src/uu/expand/locales/en-US.ftl index ad15acf39..c295d495c 100644 --- a/src/uu/expand/locales/en-US.ftl +++ b/src/uu/expand/locales/en-US.ftl @@ -1,3 +1,18 @@ expand-about = Convert tabs in each FILE to spaces, writing to standard output. With no FILE, or when FILE is -, read standard input. expand-usage = expand [OPTION]... [FILE]... + +# Help messages +expand-help-initial = do not convert tabs after non blanks +expand-help-tabs = have tabs N characters apart, not 8 or use comma separated list of explicit tab positions +expand-help-no-utf8 = interpret input file as 8-bit ASCII rather than UTF-8 + +# Error messages +expand-error-invalid-character = tab size contains invalid character(s): { $char } +expand-error-specifier-not-at-start = { $specifier } specifier not at start of number: { $number } +expand-error-specifier-only-allowed-with-last = { $specifier } specifier only allowed with the last value +expand-error-tab-size-cannot-be-zero = tab size cannot be 0 +expand-error-tab-size-too-large = tab stop is too large { $size } +expand-error-tab-sizes-must-be-ascending = tab sizes must be ascending +expand-error-is-directory = { $file }: Is a directory +expand-error-failed-to-write-output = failed to write output diff --git a/src/uu/expand/locales/fr-FR.ftl b/src/uu/expand/locales/fr-FR.ftl new file mode 100644 index 000000000..63fb3057d --- /dev/null +++ b/src/uu/expand/locales/fr-FR.ftl @@ -0,0 +1,18 @@ +expand-about = Convertir les tabulations de chaque FICHIER en espaces, en écrivant vers la sortie standard. + Sans FICHIER, ou quand FICHIER est -, lire l'entrée standard. +expand-usage = expand [OPTION]... [FICHIER]... + +# Messages d'aide +expand-help-initial = ne pas convertir les tabulations après les caractères non-blancs +expand-help-tabs = avoir des tabulations espacées de N caractères, pas 8 ou utiliser une liste séparée par des virgules de positions de tabulation explicites +expand-help-no-utf8 = interpréter le fichier d'entrée comme ASCII 8 bits plutôt que UTF-8 + +# Messages d'erreur +expand-error-invalid-character = la taille de tabulation contient des caractères invalides : { $char } +expand-error-specifier-not-at-start = le spécificateur { $specifier } n'est pas au début du nombre : { $number } +expand-error-specifier-only-allowed-with-last = le spécificateur { $specifier } n'est autorisé qu'avec la dernière valeur +expand-error-tab-size-cannot-be-zero = la taille de tabulation ne peut pas être 0 +expand-error-tab-size-too-large = l'arrêt de tabulation est trop grand { $size } +expand-error-tab-sizes-must-be-ascending = les tailles de tabulation doivent être croissantes +expand-error-is-directory = { $file } : Est un répertoire +expand-error-failed-to-write-output = échec de l'écriture de la sortie diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index 2e8d1b296..58be381d3 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -6,6 +6,7 @@ // spell-checker:ignore (ToDO) ctype cwidth iflag nbytes nspaces nums tspaces uflag Preprocess use clap::{Arg, ArgAction, ArgMatches, Command}; +use std::collections::HashMap; use std::ffi::OsString; use std::fs::File; use std::io::{BufRead, BufReader, BufWriter, Read, Write, stdin, stdout}; @@ -18,7 +19,7 @@ use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult, set_exit_code}; use uucore::{format_usage, show_error}; -use uucore::locale::get_message; +use uucore::locale::{get_message, get_message_with_args}; pub mod options { pub static TABS: &str = "tabs"; @@ -61,17 +62,17 @@ fn is_digit_or_comma(c: char) -> bool { /// Errors that can occur when parsing a `--tabs` argument. #[derive(Debug, Error)] enum ParseError { - #[error("tab size contains invalid character(s): {}", .0.quote())] + #[error("{}", get_message_with_args("expand-error-invalid-character", HashMap::from([("char".to_string(), .0.quote().to_string())])))] InvalidCharacter(String), - #[error("{} specifier not at start of number: {}", .0.quote(), .1.quote())] + #[error("{}", get_message_with_args("expand-error-specifier-not-at-start", HashMap::from([("specifier".to_string(), .0.quote().to_string()), ("number".to_string(), .1.quote().to_string())])))] SpecifierNotAtStartOfNumber(String, String), - #[error("{} specifier only allowed with the last value", .0.quote())] + #[error("{}", get_message_with_args("expand-error-specifier-only-allowed-with-last", HashMap::from([("specifier".to_string(), .0.quote().to_string())])))] SpecifierOnlyAllowedWithLastValue(String), - #[error("tab size cannot be 0")] + #[error("{}", get_message("expand-error-tab-size-cannot-be-zero"))] TabSizeCannotBeZero, - #[error("tab stop is too large {}", .0.quote())] + #[error("{}", get_message_with_args("expand-error-tab-size-too-large", HashMap::from([("size".to_string(), .0.quote().to_string())])))] TabSizeTooLarge(String), - #[error("tab sizes must be ascending")] + #[error("{}", get_message("expand-error-tab-sizes-must-be-ascending"))] TabSizesMustBeAscending, } @@ -261,7 +262,7 @@ pub fn uu_app() -> Command { Arg::new(options::INITIAL) .long(options::INITIAL) .short('i') - .help("do not convert tabs after non blanks") + .help(get_message("expand-help-initial")) .action(ArgAction::SetTrue), ) .arg( @@ -270,16 +271,13 @@ pub fn uu_app() -> Command { .short('t') .value_name("N, LIST") .action(ArgAction::Append) - .help( - "have tabs N characters apart, not 8 or use comma separated list \ - of explicit tab positions", - ), + .help(get_message("expand-help-tabs")), ) .arg( Arg::new(options::NO_UTF8) .long(options::NO_UTF8) .short('U') - .help("interpret input file as 8-bit ASCII rather than UTF-8") + .help(get_message("expand-help-no-utf8")) .action(ArgAction::SetTrue), ) .arg( @@ -447,7 +445,13 @@ fn expand(options: &Options) -> UResult<()> { for file in &options.files { if Path::new(file).is_dir() { - show_error!("{file}: Is a directory"); + show_error!( + "{}", + get_message_with_args( + "expand-error-is-directory", + HashMap::from([("file".to_string(), file.to_string())]) + ) + ); set_exit_code(1); continue; } @@ -458,7 +462,7 @@ fn expand(options: &Options) -> UResult<()> { Err(_) => buf.is_empty(), } { expand_line(&mut buf, &mut output, ts, options) - .map_err_context(|| "failed to write output".to_string())?; + .map_err_context(|| get_message("expand-error-failed-to-write-output"))?; } } Err(e) => {