diff --git a/src/uu/nl/locales/en-US.ftl b/src/uu/nl/locales/en-US.ftl index 7880de562..548d5eec2 100644 --- a/src/uu/nl/locales/en-US.ftl +++ b/src/uu/nl/locales/en-US.ftl @@ -13,3 +13,27 @@ nl-after-help = STYLE is one of: - ln left justified, no leading zeros - rn right justified, no leading zeros - rz right justified, leading zeros + +# Help messages +nl-help-help = Print help information. +nl-help-body-numbering = use STYLE for numbering body lines +nl-help-section-delimiter = use CC for separating logical pages +nl-help-footer-numbering = use STYLE for numbering footer lines +nl-help-header-numbering = use STYLE for numbering header lines +nl-help-line-increment = line number increment at each line +nl-help-join-blank-lines = group of NUMBER empty lines counted as one +nl-help-number-format = insert line numbers according to FORMAT +nl-help-no-renumber = do not reset line numbers at logical pages +nl-help-number-separator = add STRING after (possible) line number +nl-help-starting-line-number = first line number on each logical page +nl-help-number-width = use NUMBER columns for line numbers + +# Error messages +nl-error-invalid-arguments = Invalid arguments supplied. +nl-error-could-not-read-line = could not read line +nl-error-line-number-overflow = line number overflow +nl-error-invalid-line-width = Invalid line number field width: ‘{ $value }’: Numerical result out of range +nl-error-invalid-blank-lines = Invalid line number of blank lines: ‘{ $value }’: Numerical result out of range +nl-error-invalid-regex = invalid regular expression +nl-error-invalid-numbering-style = invalid numbering style: '{ $style }' +nl-error-is-directory = { $path }: Is a directory diff --git a/src/uu/nl/locales/fr-FR.ftl b/src/uu/nl/locales/fr-FR.ftl new file mode 100644 index 000000000..e18fcdcb3 --- /dev/null +++ b/src/uu/nl/locales/fr-FR.ftl @@ -0,0 +1,39 @@ +nl-about = Numéroter les lignes des fichiers +nl-usage = nl [OPTION]... [FICHIER]... +nl-after-help = STYLE est l'un des suivants : + + - a numéroter toutes les lignes + - t numéroter seulement les lignes non vides + - n ne numéroter aucune ligne + - pBRE numéroter seulement les lignes qui contiennent une correspondance pour + l'expression régulière de base, BRE + + FORMAT est l'un des suivants : + + - ln justifié à gauche, sans zéros en tête + - rn justifié à droite, sans zéros en tête + - rz justifié à droite, avec zéros en tête + +# Messages d'aide +nl-help-help = Afficher les informations d'aide. +nl-help-body-numbering = utiliser STYLE pour numéroter les lignes du corps +nl-help-section-delimiter = utiliser CC pour séparer les pages logiques +nl-help-footer-numbering = utiliser STYLE pour numéroter les lignes de pied de page +nl-help-header-numbering = utiliser STYLE pour numéroter les lignes d'en-tête +nl-help-line-increment = incrément du numéro de ligne à chaque ligne +nl-help-join-blank-lines = groupe de NUMBER lignes vides comptées comme une seule +nl-help-number-format = insérer les numéros de ligne selon FORMAT +nl-help-no-renumber = ne pas remettre à zéro les numéros de ligne aux pages logiques +nl-help-number-separator = ajouter STRING après le numéro de ligne (éventuel) +nl-help-starting-line-number = premier numéro de ligne sur chaque page logique +nl-help-number-width = utiliser NUMBER colonnes pour les numéros de ligne + +# Messages d'erreur +nl-error-invalid-arguments = Arguments fournis invalides. +nl-error-could-not-read-line = impossible de lire la ligne +nl-error-line-number-overflow = débordement du numéro de ligne +nl-error-invalid-line-width = Largeur de champ de numéro de ligne invalide : ‘{ $value }’ : Résultat numérique hors limites +nl-error-invalid-blank-lines = Nombre de lignes vides invalide : ‘{ $value }’ : Résultat numérique hors limites +nl-error-invalid-regex = expression régulière invalide +nl-error-invalid-numbering-style = style de numérotation invalide : '{ $style }' +nl-error-is-directory = { $path } : Est un répertoire diff --git a/src/uu/nl/src/helper.rs b/src/uu/nl/src/helper.rs index 3e5a96b9c..aec6765f3 100644 --- a/src/uu/nl/src/helper.rs +++ b/src/uu/nl/src/helper.rs @@ -5,6 +5,8 @@ // spell-checker:ignore (ToDO) conv use crate::options; +use std::collections::HashMap; +use uucore::locale::get_message_with_args; // parse_options loads the options into the settings, returning an array of // error messages. @@ -59,15 +61,17 @@ pub fn parse_options(settings: &mut crate::Settings, opts: &clap::ArgMatches) -> match opts.get_one::(options::NUMBER_WIDTH) { None => {} Some(num) if *num > 0 => settings.number_width = *num, - Some(_) => errs.push(String::from( - "Invalid line number field width: ‘0’: Numerical result out of range", + Some(_) => errs.push(get_message_with_args( + "nl-error-invalid-line-width", + HashMap::from([("value".to_string(), "0".to_string())]), )), } match opts.get_one::(options::JOIN_BLANK_LINES) { None => {} Some(num) if *num > 0 => settings.join_blank_lines = *num, - Some(_) => errs.push(String::from( - "Invalid line number of blank lines: ‘0’: Numerical result out of range", + Some(_) => errs.push(get_message_with_args( + "nl-error-invalid-blank-lines", + HashMap::from([("value".to_string(), "0".to_string())]), )), } if let Some(num) = opts.get_one::(options::LINE_INCREMENT) { diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index 0b6397dfe..6678a1de9 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -4,11 +4,12 @@ // file that was distributed with this source code. use clap::{Arg, ArgAction, Command}; +use std::collections::HashMap; use std::fs::File; use std::io::{BufRead, BufReader, Read, stdin}; use std::path::Path; use uucore::error::{FromIo, UResult, USimpleError, set_exit_code}; -use uucore::locale::get_message; +use uucore::locale::{get_message, get_message_with_args}; use uucore::{format_usage, show_error}; mod helper; @@ -89,9 +90,12 @@ impl TryFrom<&str> for NumberingStyle { "n" => Ok(Self::None), _ if s.starts_with('p') => match regex::Regex::new(&s[1..]) { Ok(re) => Ok(Self::Regex(Box::new(re))), - Err(_) => Err(String::from("invalid regular expression")), + Err(_) => Err(get_message("nl-error-invalid-regex")), }, - _ => Err(format!("invalid numbering style: '{s}'")), + _ => Err(get_message_with_args( + "nl-error-invalid-numbering-style", + HashMap::from([("style".to_string(), s.to_string())]), + )), } } } @@ -185,7 +189,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if !parse_errors.is_empty() { return Err(USimpleError::new( 1, - format!("Invalid arguments supplied.\n{}", parse_errors.join("\n")), + format!( + "{}\n{}", + get_message("nl-error-invalid-arguments"), + parse_errors.join("\n") + ), )); } @@ -204,7 +212,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let path = Path::new(file); if path.is_dir() { - show_error!("{}: Is a directory", path.display()); + show_error!( + "{}", + get_message_with_args( + "nl-error-is-directory", + HashMap::from([("path".to_string(), path.display().to_string())]) + ) + ); set_exit_code(1); } else { let reader = File::open(path).map_err_context(|| file.to_string())?; @@ -228,7 +242,7 @@ pub fn uu_app() -> Command { .arg( Arg::new(options::HELP) .long(options::HELP) - .help("Print help information.") + .help(get_message("nl-help-help")) .action(ArgAction::Help), ) .arg( @@ -241,35 +255,35 @@ pub fn uu_app() -> Command { Arg::new(options::BODY_NUMBERING) .short('b') .long(options::BODY_NUMBERING) - .help("use STYLE for numbering body lines") + .help(get_message("nl-help-body-numbering")) .value_name("STYLE"), ) .arg( Arg::new(options::SECTION_DELIMITER) .short('d') .long(options::SECTION_DELIMITER) - .help("use CC for separating logical pages") + .help(get_message("nl-help-section-delimiter")) .value_name("CC"), ) .arg( Arg::new(options::FOOTER_NUMBERING) .short('f') .long(options::FOOTER_NUMBERING) - .help("use STYLE for numbering footer lines") + .help(get_message("nl-help-footer-numbering")) .value_name("STYLE"), ) .arg( Arg::new(options::HEADER_NUMBERING) .short('h') .long(options::HEADER_NUMBERING) - .help("use STYLE for numbering header lines") + .help(get_message("nl-help-header-numbering")) .value_name("STYLE"), ) .arg( Arg::new(options::LINE_INCREMENT) .short('i') .long(options::LINE_INCREMENT) - .help("line number increment at each line") + .help(get_message("nl-help-line-increment")) .value_name("NUMBER") .value_parser(clap::value_parser!(i64)), ) @@ -277,7 +291,7 @@ pub fn uu_app() -> Command { Arg::new(options::JOIN_BLANK_LINES) .short('l') .long(options::JOIN_BLANK_LINES) - .help("group of NUMBER empty lines counted as one") + .help(get_message("nl-help-join-blank-lines")) .value_name("NUMBER") .value_parser(clap::value_parser!(u64)), ) @@ -285,7 +299,7 @@ pub fn uu_app() -> Command { Arg::new(options::NUMBER_FORMAT) .short('n') .long(options::NUMBER_FORMAT) - .help("insert line numbers according to FORMAT") + .help(get_message("nl-help-number-format")) .value_name("FORMAT") .value_parser(["ln", "rn", "rz"]), ) @@ -293,21 +307,21 @@ pub fn uu_app() -> Command { Arg::new(options::NO_RENUMBER) .short('p') .long(options::NO_RENUMBER) - .help("do not reset line numbers at logical pages") + .help(get_message("nl-help-no-renumber")) .action(ArgAction::SetFalse), ) .arg( Arg::new(options::NUMBER_SEPARATOR) .short('s') .long(options::NUMBER_SEPARATOR) - .help("add STRING after (possible) line number") + .help(get_message("nl-help-number-separator")) .value_name("STRING"), ) .arg( Arg::new(options::STARTING_LINE_NUMBER) .short('v') .long(options::STARTING_LINE_NUMBER) - .help("first line number on each logical page") + .help(get_message("nl-help-starting-line-number")) .value_name("NUMBER") .value_parser(clap::value_parser!(i64)), ) @@ -315,7 +329,7 @@ pub fn uu_app() -> Command { Arg::new(options::NUMBER_WIDTH) .short('w') .long(options::NUMBER_WIDTH) - .help("use NUMBER columns for line numbers") + .help(get_message("nl-help-number-width")) .value_name("NUMBER") .value_parser(clap::value_parser!(usize)), ) @@ -326,7 +340,7 @@ fn nl(reader: &mut BufReader, stats: &mut Stats, settings: &Settings let mut current_numbering_style = &settings.body_numbering; for line in reader.lines() { - let line = line.map_err_context(|| "could not read line".to_string())?; + let line = line.map_err_context(|| get_message("nl-error-could-not-read-line"))?; if line.is_empty() { stats.consecutive_empty_lines += 1; @@ -366,7 +380,10 @@ fn nl(reader: &mut BufReader, stats: &mut Stats, settings: &Settings if is_line_numbered { let Some(line_number) = stats.line_number else { - return Err(USimpleError::new(1, "line number overflow")); + return Err(USimpleError::new( + 1, + get_message("nl-error-line-number-overflow"), + )); }; println!( "{}{}{line}",