mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #8181 from sylvestre/l10n-nl
l10n: port nl for translation + add french
This commit is contained in:
commit
df94746a4e
4 changed files with 107 additions and 23 deletions
|
@ -13,3 +13,27 @@ nl-after-help = STYLE is one of:
|
||||||
- ln left justified, no leading zeros
|
- ln left justified, no leading zeros
|
||||||
- rn right justified, no leading zeros
|
- rn right justified, no leading zeros
|
||||||
- rz right justified, 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
|
||||||
|
|
39
src/uu/nl/locales/fr-FR.ftl
Normal file
39
src/uu/nl/locales/fr-FR.ftl
Normal file
|
@ -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
|
|
@ -5,6 +5,8 @@
|
||||||
// spell-checker:ignore (ToDO) conv
|
// spell-checker:ignore (ToDO) conv
|
||||||
|
|
||||||
use crate::options;
|
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
|
// parse_options loads the options into the settings, returning an array of
|
||||||
// error messages.
|
// error messages.
|
||||||
|
@ -59,15 +61,17 @@ pub fn parse_options(settings: &mut crate::Settings, opts: &clap::ArgMatches) ->
|
||||||
match opts.get_one::<usize>(options::NUMBER_WIDTH) {
|
match opts.get_one::<usize>(options::NUMBER_WIDTH) {
|
||||||
None => {}
|
None => {}
|
||||||
Some(num) if *num > 0 => settings.number_width = *num,
|
Some(num) if *num > 0 => settings.number_width = *num,
|
||||||
Some(_) => errs.push(String::from(
|
Some(_) => errs.push(get_message_with_args(
|
||||||
"Invalid line number field width: ‘0’: Numerical result out of range",
|
"nl-error-invalid-line-width",
|
||||||
|
HashMap::from([("value".to_string(), "0".to_string())]),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
match opts.get_one::<u64>(options::JOIN_BLANK_LINES) {
|
match opts.get_one::<u64>(options::JOIN_BLANK_LINES) {
|
||||||
None => {}
|
None => {}
|
||||||
Some(num) if *num > 0 => settings.join_blank_lines = *num,
|
Some(num) if *num > 0 => settings.join_blank_lines = *num,
|
||||||
Some(_) => errs.push(String::from(
|
Some(_) => errs.push(get_message_with_args(
|
||||||
"Invalid line number of blank lines: ‘0’: Numerical result out of range",
|
"nl-error-invalid-blank-lines",
|
||||||
|
HashMap::from([("value".to_string(), "0".to_string())]),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
if let Some(num) = opts.get_one::<i64>(options::LINE_INCREMENT) {
|
if let Some(num) = opts.get_one::<i64>(options::LINE_INCREMENT) {
|
||||||
|
|
|
@ -4,11 +4,12 @@
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
use clap::{Arg, ArgAction, Command};
|
use clap::{Arg, ArgAction, Command};
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader, Read, stdin};
|
use std::io::{BufRead, BufReader, Read, stdin};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use uucore::error::{FromIo, UResult, USimpleError, set_exit_code};
|
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};
|
use uucore::{format_usage, show_error};
|
||||||
|
|
||||||
mod helper;
|
mod helper;
|
||||||
|
@ -89,9 +90,12 @@ impl TryFrom<&str> for NumberingStyle {
|
||||||
"n" => Ok(Self::None),
|
"n" => Ok(Self::None),
|
||||||
_ if s.starts_with('p') => match regex::Regex::new(&s[1..]) {
|
_ if s.starts_with('p') => match regex::Regex::new(&s[1..]) {
|
||||||
Ok(re) => Ok(Self::Regex(Box::new(re))),
|
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() {
|
if !parse_errors.is_empty() {
|
||||||
return Err(USimpleError::new(
|
return Err(USimpleError::new(
|
||||||
1,
|
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);
|
let path = Path::new(file);
|
||||||
|
|
||||||
if path.is_dir() {
|
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);
|
set_exit_code(1);
|
||||||
} else {
|
} else {
|
||||||
let reader = File::open(path).map_err_context(|| file.to_string())?;
|
let reader = File::open(path).map_err_context(|| file.to_string())?;
|
||||||
|
@ -228,7 +242,7 @@ pub fn uu_app() -> Command {
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::HELP)
|
Arg::new(options::HELP)
|
||||||
.long(options::HELP)
|
.long(options::HELP)
|
||||||
.help("Print help information.")
|
.help(get_message("nl-help-help"))
|
||||||
.action(ArgAction::Help),
|
.action(ArgAction::Help),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -241,35 +255,35 @@ pub fn uu_app() -> Command {
|
||||||
Arg::new(options::BODY_NUMBERING)
|
Arg::new(options::BODY_NUMBERING)
|
||||||
.short('b')
|
.short('b')
|
||||||
.long(options::BODY_NUMBERING)
|
.long(options::BODY_NUMBERING)
|
||||||
.help("use STYLE for numbering body lines")
|
.help(get_message("nl-help-body-numbering"))
|
||||||
.value_name("STYLE"),
|
.value_name("STYLE"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::SECTION_DELIMITER)
|
Arg::new(options::SECTION_DELIMITER)
|
||||||
.short('d')
|
.short('d')
|
||||||
.long(options::SECTION_DELIMITER)
|
.long(options::SECTION_DELIMITER)
|
||||||
.help("use CC for separating logical pages")
|
.help(get_message("nl-help-section-delimiter"))
|
||||||
.value_name("CC"),
|
.value_name("CC"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::FOOTER_NUMBERING)
|
Arg::new(options::FOOTER_NUMBERING)
|
||||||
.short('f')
|
.short('f')
|
||||||
.long(options::FOOTER_NUMBERING)
|
.long(options::FOOTER_NUMBERING)
|
||||||
.help("use STYLE for numbering footer lines")
|
.help(get_message("nl-help-footer-numbering"))
|
||||||
.value_name("STYLE"),
|
.value_name("STYLE"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::HEADER_NUMBERING)
|
Arg::new(options::HEADER_NUMBERING)
|
||||||
.short('h')
|
.short('h')
|
||||||
.long(options::HEADER_NUMBERING)
|
.long(options::HEADER_NUMBERING)
|
||||||
.help("use STYLE for numbering header lines")
|
.help(get_message("nl-help-header-numbering"))
|
||||||
.value_name("STYLE"),
|
.value_name("STYLE"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::LINE_INCREMENT)
|
Arg::new(options::LINE_INCREMENT)
|
||||||
.short('i')
|
.short('i')
|
||||||
.long(options::LINE_INCREMENT)
|
.long(options::LINE_INCREMENT)
|
||||||
.help("line number increment at each line")
|
.help(get_message("nl-help-line-increment"))
|
||||||
.value_name("NUMBER")
|
.value_name("NUMBER")
|
||||||
.value_parser(clap::value_parser!(i64)),
|
.value_parser(clap::value_parser!(i64)),
|
||||||
)
|
)
|
||||||
|
@ -277,7 +291,7 @@ pub fn uu_app() -> Command {
|
||||||
Arg::new(options::JOIN_BLANK_LINES)
|
Arg::new(options::JOIN_BLANK_LINES)
|
||||||
.short('l')
|
.short('l')
|
||||||
.long(options::JOIN_BLANK_LINES)
|
.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_name("NUMBER")
|
||||||
.value_parser(clap::value_parser!(u64)),
|
.value_parser(clap::value_parser!(u64)),
|
||||||
)
|
)
|
||||||
|
@ -285,7 +299,7 @@ pub fn uu_app() -> Command {
|
||||||
Arg::new(options::NUMBER_FORMAT)
|
Arg::new(options::NUMBER_FORMAT)
|
||||||
.short('n')
|
.short('n')
|
||||||
.long(options::NUMBER_FORMAT)
|
.long(options::NUMBER_FORMAT)
|
||||||
.help("insert line numbers according to FORMAT")
|
.help(get_message("nl-help-number-format"))
|
||||||
.value_name("FORMAT")
|
.value_name("FORMAT")
|
||||||
.value_parser(["ln", "rn", "rz"]),
|
.value_parser(["ln", "rn", "rz"]),
|
||||||
)
|
)
|
||||||
|
@ -293,21 +307,21 @@ pub fn uu_app() -> Command {
|
||||||
Arg::new(options::NO_RENUMBER)
|
Arg::new(options::NO_RENUMBER)
|
||||||
.short('p')
|
.short('p')
|
||||||
.long(options::NO_RENUMBER)
|
.long(options::NO_RENUMBER)
|
||||||
.help("do not reset line numbers at logical pages")
|
.help(get_message("nl-help-no-renumber"))
|
||||||
.action(ArgAction::SetFalse),
|
.action(ArgAction::SetFalse),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::NUMBER_SEPARATOR)
|
Arg::new(options::NUMBER_SEPARATOR)
|
||||||
.short('s')
|
.short('s')
|
||||||
.long(options::NUMBER_SEPARATOR)
|
.long(options::NUMBER_SEPARATOR)
|
||||||
.help("add STRING after (possible) line number")
|
.help(get_message("nl-help-number-separator"))
|
||||||
.value_name("STRING"),
|
.value_name("STRING"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::STARTING_LINE_NUMBER)
|
Arg::new(options::STARTING_LINE_NUMBER)
|
||||||
.short('v')
|
.short('v')
|
||||||
.long(options::STARTING_LINE_NUMBER)
|
.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_name("NUMBER")
|
||||||
.value_parser(clap::value_parser!(i64)),
|
.value_parser(clap::value_parser!(i64)),
|
||||||
)
|
)
|
||||||
|
@ -315,7 +329,7 @@ pub fn uu_app() -> Command {
|
||||||
Arg::new(options::NUMBER_WIDTH)
|
Arg::new(options::NUMBER_WIDTH)
|
||||||
.short('w')
|
.short('w')
|
||||||
.long(options::NUMBER_WIDTH)
|
.long(options::NUMBER_WIDTH)
|
||||||
.help("use NUMBER columns for line numbers")
|
.help(get_message("nl-help-number-width"))
|
||||||
.value_name("NUMBER")
|
.value_name("NUMBER")
|
||||||
.value_parser(clap::value_parser!(usize)),
|
.value_parser(clap::value_parser!(usize)),
|
||||||
)
|
)
|
||||||
|
@ -326,7 +340,7 @@ fn nl<T: Read>(reader: &mut BufReader<T>, stats: &mut Stats, settings: &Settings
|
||||||
let mut current_numbering_style = &settings.body_numbering;
|
let mut current_numbering_style = &settings.body_numbering;
|
||||||
|
|
||||||
for line in reader.lines() {
|
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() {
|
if line.is_empty() {
|
||||||
stats.consecutive_empty_lines += 1;
|
stats.consecutive_empty_lines += 1;
|
||||||
|
@ -366,7 +380,10 @@ fn nl<T: Read>(reader: &mut BufReader<T>, stats: &mut Stats, settings: &Settings
|
||||||
|
|
||||||
if is_line_numbered {
|
if is_line_numbered {
|
||||||
let Some(line_number) = stats.line_number else {
|
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!(
|
println!(
|
||||||
"{}{}{line}",
|
"{}{}{line}",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue