1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

Merge pull request #8147 from sylvestre/l10n-csplit

l10n: port csplit for translation + add french
This commit is contained in:
Daniel Hofstetter 2025-06-25 10:17:45 +02:00 committed by GitHub
commit a7c8eb8acb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 91 additions and 23 deletions

View file

@ -1,3 +1,29 @@
csplit-about = Split a file into sections determined by context lines csplit-about = Split a file into sections determined by context lines
csplit-usage = csplit [OPTION]... FILE PATTERN... csplit-usage = csplit [OPTION]... FILE PATTERN...
csplit-after-help = Output pieces of FILE separated by PATTERN(s) to files 'xx00', 'xx01', ..., and output byte counts of each piece to standard output. csplit-after-help = Output pieces of FILE separated by PATTERN(s) to files 'xx00', 'xx01', ..., and output byte counts of each piece to standard output.
# Help messages
csplit-help-suffix-format = use sprintf FORMAT instead of %02d
csplit-help-prefix = use PREFIX instead of 'xx'
csplit-help-keep-files = do not remove output files on errors
csplit-help-suppress-matched = suppress the lines matching PATTERN
csplit-help-digits = use specified number of digits instead of 2
csplit-help-quiet = do not print counts of output file sizes
csplit-help-elide-empty-files = remove empty output files
# Error messages
csplit-error-line-out-of-range = { $pattern }: line number out of range
csplit-error-line-out-of-range-on-repetition = { $pattern }: line number out of range on repetition { $repetition }
csplit-error-match-not-found = { $pattern }: match not found
csplit-error-match-not-found-on-repetition = { $pattern }: match not found on repetition { $repetition }
csplit-error-line-number-is-zero = 0: line number must be greater than zero
csplit-error-line-number-smaller-than-previous = line number '{ $current }' is smaller than preceding line number, { $previous }
csplit-error-invalid-pattern = { $pattern }: invalid pattern
csplit-error-invalid-number = invalid number: { $number }
csplit-error-suffix-format-incorrect = incorrect conversion specification in suffix
csplit-error-suffix-format-too-many-percents = too many % conversion specifications in suffix
csplit-error-not-regular-file = { $file } is not a regular file
csplit-warning-line-number-same-as-previous = line number '{ $line_number }' is the same as preceding line number
csplit-stream-not-utf8 = stream did not contain valid UTF-8
csplit-read-error = read error
csplit-write-split-not-created = trying to write to a split that was not created

View file

@ -0,0 +1,29 @@
csplit-about = Diviser un fichier en sections déterminées par des lignes de contexte
csplit-usage = csplit [OPTION]... FICHIER MOTIF...
csplit-after-help = Sortir les morceaux de FICHIER séparés par MOTIF(S) dans les fichiers 'xx00', 'xx01', ..., et sortir le nombre d'octets de chaque morceau sur la sortie standard.
# Messages d'aide
csplit-help-suffix-format = utiliser le FORMAT sprintf au lieu de %02d
csplit-help-prefix = utiliser PRÉFIXE au lieu de 'xx'
csplit-help-keep-files = ne pas supprimer les fichiers de sortie en cas d'erreurs
csplit-help-suppress-matched = supprimer les lignes correspondant au MOTIF
csplit-help-digits = utiliser le nombre spécifié de chiffres au lieu de 2
csplit-help-quiet = ne pas afficher le nombre d'octets des fichiers de sortie
csplit-help-elide-empty-files = supprimer les fichiers de sortie vides
# Messages d'erreur
csplit-error-line-out-of-range = { $pattern } : numéro de ligne hors limites
csplit-error-line-out-of-range-on-repetition = { $pattern } : numéro de ligne hors limites à la répétition { $repetition }
csplit-error-match-not-found = { $pattern } : correspondance non trouvée
csplit-error-match-not-found-on-repetition = { $pattern } : correspondance non trouvée à la répétition { $repetition }
csplit-error-line-number-is-zero = 0 : le numéro de ligne doit être supérieur à zéro
csplit-error-line-number-smaller-than-previous = le numéro de ligne '{ $current }' est plus petit que le numéro de ligne précédent, { $previous }
csplit-error-invalid-pattern = { $pattern } : motif invalide
csplit-error-invalid-number = nombre invalide : { $number }
csplit-error-suffix-format-incorrect = spécification de conversion incorrecte dans le suffixe
csplit-error-suffix-format-too-many-percents = trop de spécifications de conversion % dans le suffixe
csplit-error-not-regular-file = { $file } n'est pas un fichier régulier
csplit-warning-line-number-same-as-previous = le numéro de ligne '{ $line_number }' est identique au numéro de ligne précédent
csplit-stream-not-utf8 = le flux ne contenait pas d'UTF-8 valide
csplit-read-error = erreur de lecture
csplit-write-split-not-created = tentative d'écriture dans une division qui n'a pas été créée

View file

@ -85,7 +85,10 @@ impl<T: BufRead> Iterator for LinesWithNewlines<T> {
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
fn ret(v: Vec<u8>) -> io::Result<String> { fn ret(v: Vec<u8>) -> io::Result<String> {
String::from_utf8(v).map_err(|_| { String::from_utf8(v).map_err(|_| {
io::Error::new(ErrorKind::InvalidData, "stream did not contain valid UTF-8") io::Error::new(
ErrorKind::InvalidData,
get_message("csplit-stream-not-utf8"),
)
}) })
} }
@ -115,7 +118,7 @@ where
T: BufRead, T: BufRead,
{ {
let enumerated_input_lines = LinesWithNewlines::new(input) let enumerated_input_lines = LinesWithNewlines::new(input)
.map(|line| line.map_err_context(|| "read error".to_string())) .map(|line| line.map_err_context(|| get_message("csplit-read-error")))
.enumerate(); .enumerate();
let mut input_iter = InputSplitter::new(enumerated_input_lines); let mut input_iter = InputSplitter::new(enumerated_input_lines);
let mut split_writer = SplitWriter::new(options); let mut split_writer = SplitWriter::new(options);
@ -283,7 +286,7 @@ impl SplitWriter<'_> {
current_writer.write_all(bytes)?; current_writer.write_all(bytes)?;
self.size += bytes.len(); self.size += bytes.len();
} }
None => panic!("trying to write to a split that was not created"), None => panic!("{}", get_message("csplit-write-split-not-created")),
} }
} }
Ok(()) Ok(())
@ -638,26 +641,26 @@ pub fn uu_app() -> Command {
.short('b') .short('b')
.long(options::SUFFIX_FORMAT) .long(options::SUFFIX_FORMAT)
.value_name("FORMAT") .value_name("FORMAT")
.help("use sprintf FORMAT instead of %02d"), .help(get_message("csplit-help-suffix-format")),
) )
.arg( .arg(
Arg::new(options::PREFIX) Arg::new(options::PREFIX)
.short('f') .short('f')
.long(options::PREFIX) .long(options::PREFIX)
.value_name("PREFIX") .value_name("PREFIX")
.help("use PREFIX instead of 'xx'"), .help(get_message("csplit-help-prefix")),
) )
.arg( .arg(
Arg::new(options::KEEP_FILES) Arg::new(options::KEEP_FILES)
.short('k') .short('k')
.long(options::KEEP_FILES) .long(options::KEEP_FILES)
.help("do not remove output files on errors") .help(get_message("csplit-help-keep-files"))
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::SUPPRESS_MATCHED) Arg::new(options::SUPPRESS_MATCHED)
.long(options::SUPPRESS_MATCHED) .long(options::SUPPRESS_MATCHED)
.help("suppress the lines matching PATTERN") .help(get_message("csplit-help-suppress-matched"))
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue),
) )
.arg( .arg(
@ -665,7 +668,7 @@ pub fn uu_app() -> Command {
.short('n') .short('n')
.long(options::DIGITS) .long(options::DIGITS)
.value_name("DIGITS") .value_name("DIGITS")
.help("use specified number of digits instead of 2"), .help(get_message("csplit-help-digits")),
) )
.arg( .arg(
Arg::new(options::QUIET) Arg::new(options::QUIET)
@ -673,14 +676,14 @@ pub fn uu_app() -> Command {
.long(options::QUIET) .long(options::QUIET)
.visible_short_alias('s') .visible_short_alias('s')
.visible_alias("silent") .visible_alias("silent")
.help("do not print counts of output file sizes") .help(get_message("csplit-help-quiet"))
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::ELIDE_EMPTY_FILES) Arg::new(options::ELIDE_EMPTY_FILES)
.short('z') .short('z')
.long(options::ELIDE_EMPTY_FILES) .long(options::ELIDE_EMPTY_FILES)
.help("remove empty output files") .help(get_message("csplit-help-elide-empty-files"))
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue),
) )
.arg( .arg(

View file

@ -2,38 +2,40 @@
// //
// For the full copyright and license information, please view the LICENSE // For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code. // file that was distributed with this source code.
use std::collections::HashMap;
use std::io; use std::io;
use thiserror::Error; use thiserror::Error;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::UError; use uucore::error::UError;
use uucore::locale::{get_message, get_message_with_args};
/// Errors thrown by the csplit command /// Errors thrown by the csplit command
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum CsplitError { pub enum CsplitError {
#[error("IO error: {}", _0)] #[error("IO error: {}", _0)]
IoError(#[from] io::Error), IoError(#[from] io::Error),
#[error("{}: line number out of range", ._0.quote())] #[error("{}", get_message_with_args("csplit-error-line-out-of-range", HashMap::from([("pattern".to_string(), _0.quote().to_string())])))]
LineOutOfRange(String), LineOutOfRange(String),
#[error("{}: line number out of range on repetition {}", ._0.quote(), _1)] #[error("{}", get_message_with_args("csplit-error-line-out-of-range-on-repetition", HashMap::from([("pattern".to_string(), _0.quote().to_string()), ("repetition".to_string(), _1.to_string())])))]
LineOutOfRangeOnRepetition(String, usize), LineOutOfRangeOnRepetition(String, usize),
#[error("{}: match not found", ._0.quote())] #[error("{}", get_message_with_args("csplit-error-match-not-found", HashMap::from([("pattern".to_string(), _0.quote().to_string())])))]
MatchNotFound(String), MatchNotFound(String),
#[error("{}: match not found on repetition {}", ._0.quote(), _1)] #[error("{}", get_message_with_args("csplit-error-match-not-found-on-repetition", HashMap::from([("pattern".to_string(), _0.quote().to_string()), ("repetition".to_string(), _1.to_string())])))]
MatchNotFoundOnRepetition(String, usize), MatchNotFoundOnRepetition(String, usize),
#[error("0: line number must be greater than zero")] #[error("{}", get_message("csplit-error-line-number-is-zero"))]
LineNumberIsZero, LineNumberIsZero,
#[error("line number '{}' is smaller than preceding line number, {}", _0, _1)] #[error("{}", get_message_with_args("csplit-error-line-number-smaller-than-previous", HashMap::from([("current".to_string(), _0.to_string()), ("previous".to_string(), _1.to_string())])))]
LineNumberSmallerThanPrevious(usize, usize), LineNumberSmallerThanPrevious(usize, usize),
#[error("{}: invalid pattern", ._0.quote())] #[error("{}", get_message_with_args("csplit-error-invalid-pattern", HashMap::from([("pattern".to_string(), _0.quote().to_string())])))]
InvalidPattern(String), InvalidPattern(String),
#[error("invalid number: {}", ._0.quote())] #[error("{}", get_message_with_args("csplit-error-invalid-number", HashMap::from([("number".to_string(), _0.quote().to_string())])))]
InvalidNumber(String), InvalidNumber(String),
#[error("incorrect conversion specification in suffix")] #[error("{}", get_message("csplit-error-suffix-format-incorrect"))]
SuffixFormatIncorrect, SuffixFormatIncorrect,
#[error("too many % conversion specifications in suffix")] #[error("{}", get_message("csplit-error-suffix-format-too-many-percents"))]
SuffixFormatTooManyPercents, SuffixFormatTooManyPercents,
#[error("{} is not a regular file", ._0.quote())] #[error("{}", get_message_with_args("csplit-error-not-regular-file", HashMap::from([("file".to_string(), _0.quote().to_string())])))]
NotRegularFile(String), NotRegularFile(String),
#[error("{}", _0)] #[error("{}", _0)]
UError(Box<dyn UError>), UError(Box<dyn UError>),

View file

@ -6,6 +6,8 @@
use crate::csplit_error::CsplitError; use crate::csplit_error::CsplitError;
use regex::Regex; use regex::Regex;
use std::collections::HashMap;
use uucore::locale::get_message_with_args;
use uucore::show_warning; use uucore::show_warning;
/// The definition of a pattern to match on a line. /// The definition of a pattern to match on a line.
@ -168,7 +170,13 @@ fn validate_line_numbers(patterns: &[Pattern]) -> Result<(), CsplitError> {
(_, 0) => Err(CsplitError::LineNumberIsZero), (_, 0) => Err(CsplitError::LineNumberIsZero),
// two consecutive numbers should not be equal // two consecutive numbers should not be equal
(n, m) if n == m => { (n, m) if n == m => {
show_warning!("line number '{n}' is the same as preceding line number"); show_warning!(
"{}",
get_message_with_args(
"csplit-warning-line-number-same-as-previous",
HashMap::from([("line_number".to_string(), n.to_string())])
)
);
Ok(n) Ok(n)
} }
// a number cannot be greater than the one that follows // a number cannot be greater than the one that follows