8000 Merge pull request #8147 from sylvestre/l10n-csplit · uutils/coreutils@a7c8eb8 · GitHub
[go: up one dir, main page]

Skip to content

Commit a7c8eb8

Browse files
authored
Merge pull request #8147 from sylvestre/l10n-csplit
l10n: port csplit for translation + add french
2 parents 9e57ce8 + 7fe550a commit a7c8eb8

File tree

5 files changed

+91
-23
lines changed

5 files changed

+91
-23
lines changed

src/uu/csplit/locales/en-US.ftl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
11
csplit-about = Split a file into sections determined by context lines
22
csplit-usage = csplit [OPTION]... FILE PATTERN...
33
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.
4+
5+
# Help messages
6+
csplit-help-suffix-format = use sprintf FORMAT instead of %02d
7+
csplit-help-prefix = use PREFIX instead of 'xx'
8+
csplit-help-keep-files = do not remove output files on errors
9+
csplit-help-suppress-matched = suppress the lines matching PATTERN
10+
csplit-help-digits = use specified number of digits instead of 2
11+
csplit-help-quiet = do not print counts of output file sizes
12+
csplit-help-elide-empty-files = remove empty output files
13+
14+
# Error messages
15+
csplit-error-line-out-of-range = { $pattern }: line number out of range
16+
csplit-error-line-out-of-range-on-repetition = { $pattern }: line number out of range on repetition { $repetition }
17+
csplit-error-match-not-found = { $pattern }: match not found
18+
csplit-error-match-not-found-on-repetition = { $pattern }: match not found on repetition { $repetition }
19+
csplit-error-line-number-is-zero = 0: line number must be greater than zero
20+
csplit-error-line-number-smaller-than-previous = line number '{ $current }' is smaller than preceding line number, { $previous }
21+
csplit-error-invalid-pattern = { $pattern }: invalid pattern
22+
csplit-error-invalid-number = invalid number: { $number }
23+
csplit-error-suffix-format-incorrect = incorrect conversion specification in suffix
24+
csplit-error-suffix-format-too-many-percents = too many % conversion specifications in suffix
25+
csplit-error-not-regular-file = { $file } is not a regular file
26+
csplit-warning-line-number-same-as-previous = line number '{ $line_number }' is the same as preceding line number
27+
csplit-stream-not-utf8 = stream did not contain valid UTF-8
28+
csplit-read-error = read error
29+
csplit-write-split-not-created = trying to write to a split that was not created

src/uu/csplit/locales/fr-FR.ftl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
csplit-about = Diviser un fichier en sections déterminées par des lignes de contexte
2+
csplit-usage = csplit [OPTION]... FICHIER MOTIF...
3+
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.
4+
5+
# Messages d'aide
6+
csplit-help-suffix-format = utiliser le FORMAT sprintf au lieu de %02d
7+
csplit-help-prefix = utiliser PRÉFIXE au lieu de 'xx'
8+
csplit-help-keep-files = ne pas supprimer les fichiers de sortie en cas d'erreurs
9+
csplit-help-suppress-matched = supprimer les lignes correspondant au MOTIF
10+
csplit-help-digits = utiliser le nombre spécifié de chiffres au lieu de 2
11+
csplit-help-quiet = ne pas afficher le nombre d'octets des fichiers de sortie
12+
csplit-help-elide-empty-files = supprimer les fichiers de sortie vides
13+
14+
# Messages d'erreur
15+
csplit-error-line-out-of-range = { $pattern } : numéro de ligne hors limites
16+
csplit-error-line-out-of-range-on-repetition = { $pattern } : numéro de ligne hors limites à la répétition { $repetition }
17+
csplit-error-match-not-found = { $pattern } : correspondance non trouvée
18+
csplit-error-match-not-found-on-repetition = { $pattern } : correspondance non trouvée à la répétition { $repetition }
19+
csplit-error-line-number-is-zero = 0 : le numéro de ligne doit être supérieur à zéro
20+
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 }
21+
csplit-error-invalid-pattern = { $pattern } : motif invalide
22+
csplit-error-invalid-number = nombre invalide : { $number }
23+
csplit-error-suffix-format-incorrect = spécification de conversion incorrecte dans le suffixe
24+
csplit-error-suffix-format-too-many-percents = trop de spécifications de conversion % dans le suffixe
25+
csplit-error-not-regular-file = { $file } n'est pas un fichier régulier
26+
csplit-warning-line-number-same-as-previous = le numéro de ligne '{ $line_number }' est identique au numéro de ligne précédent
27+
csplit-stream-not-utf8 = le flux ne contenait pas d'UTF-8 valide
28+
csplit-read-error = erreur de lecture
29+
csplit-write-split-not-created = tentative d'écriture dans une division qui n'a pas été créée

src/uu/csplit/src/csplit.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ impl<T: BufRead> Iterator for LinesWithNewlines<T> {
8585
fn next(&mut self) -> Option<Self::Item> {
8686
fn ret(v: Vec<u8>) -> io::Result<String> {
8787
String::from_utf8(v).map_err(|_| {
88-
io::Error::new(ErrorKind::InvalidData, "stream did not contain valid UTF-8")
88+
io::Error::new(
89+
ErrorKind::InvalidData,
90+
get_message("csplit-stream-not-utf8"),
91+
)
8992
})
9093
}
9194

@@ -115,7 +118,7 @@ where
115118
T: BufRead,
116119
{
117120
let enumerated_input_lines = LinesWithNewlines::new(input)
118-
.map(|line| line.map_err_context(|| "read error".to_string()))
121+
.map(|line| line.map_err_context(|| get_message("csplit-read-error")))
119122
.enumerate();
120123
let mut input_iter = InputSplitter::new(enumerated_input_lines);
121124
let mut split_writer = SplitWriter::new(options);
@@ -283,7 +286,7 @@ impl SplitWriter<'_> {
283286
current_writer.write_all(bytes)?;
284287
self.size += bytes.len();
285288
}
286-
None => panic!("trying to write to a split that was not created"),
289+
None => panic!("{}", get_message("csplit-write-split-not-created")),
287290
}
288291
}
289292
Ok(())
@@ -638,49 +641,49 @@ pub fn uu_app() -> Command {
638641
.short('b')
639642
.long(options::SUFFIX_FORMAT)
640643
.value_name("FORMAT")
641-
.help("use sprintf FORMAT instead of %02d"),
644+
.help(get_message("csplit-help-suffix-format")),
642645
)
643646
.arg(
644647
Arg::new(options::PREFIX)
645648
.short('f')
646649
.long(options::PREFIX)
647650
.value_name("PREFIX")
648-
.help("use PREFIX instead of 'xx'"),
651+
.help(get_message("csplit-help-prefix")),
649652
)
650653
.arg(
651654
Arg::new(options::KEEP_FILES)
652655
.short('k')
653656
.long(options::KEEP_FILES)
654-
.help("do not remove output files on errors")
657+
.help(get_message("csplit-help-keep-files"))
655658
.action(ArgAction::SetTrue),
656659
)
657660
.arg(
658661
Arg::new(options::SUPPRESS_MATCHED)
659662
.long(options::SUPPRESS_MATCHED)
660-
.help("suppress the lines matching PATTERN")
663+
.help(get_message("csplit-help-suppress-matched"))
661664
.action(ArgAction::SetTrue),
662665
)
663666
.arg(
664667
Arg::new(options::DIGITS)
665668
.short('n')
666669
.long(options::DIGITS)
667670
.value_name("DIGITS")
668-
.help("use specified number of digits instead of 2"),
671+
.help(get_message("csplit-help-digits")),
669672
)
670673
.arg(
671674
Arg::new(options::QUIET)
672675
.short('q')
673676
.long(options::QUIET)
674677
.visible_short_alias('s')
675678
.visible_alias("silent")
676-
.help("do not print counts of output file sizes")
679+
.help(get_message("csplit-help-quiet"))
677680
.action(ArgAction::SetTrue),
678681
)
679682
.arg(
680683
Arg::new(options::ELIDE_EMPTY_FILES)
681684
.short('z')
682685
.long(options::ELIDE_EMPTY_FILES)
683-
.help("remove empty output files")
686+
.help(get_message("csplit-help-elide-empty-files"))
684687
.action(ArgAction::SetTrue),
685688
)
686689
.arg(

src/uu/csplit/src/csplit_error.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,40 @@
22
//
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
5+
6+
use std::collections::HashMap;
57
use std::io;
68
use thiserror::Error;
7-
89
use uucore::display::Quotable;
910
use uucore::error::UError;
11+
use uucore::locale::{get_message, get_message_with_args};
1012

1113
/// Errors thrown by the csplit command
1214
#[derive(Debug, Error)]
1315
pub enum CsplitError {
1416
#[error("IO error: {}", _0)]
1517
IoError(#[from] io::Error),
16-
#[error("{}: line number out of range", ._0.quote())]
18+
#[error("{}", get_message_with_args("csplit-error-line-out-of-range", HashMap::from([("pattern".to_string(), _0.quote().to_string())])))]
1719
LineOutOfRange(String),
18-
#[error("{}: line number out of range on repetition {}", ._0.quote(), _1)]
20+
#[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())])))]
1921
LineOutOfRangeOnRepetition(String, usize),
20-
#[error("{}: match not found", ._0.quote())]
22+
#[error("{}", get_message_with_args("csplit-error-match-not-found", HashMap::from([("pattern".to_string(), _0.quote().to_string())])))]
2123
MatchNotFound(String),
22-
#[error("{}: match not found on repetition {}", ._0.quote(), _1)]
24+
#[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())])))]
2325
MatchNotFoundOnRepetition(String, usize),
24-
#[error("0: line number must be greater than zero")]
26+
#[error("{}", get_message("csplit-error-line-number-is-zero"))]
2527
LineNumberIsZero,
26-
#[error("line number '{}' is smaller than preceding line number, {}", _0, _1)]
28+
#[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())])))]
2729
LineNumberSmallerThanPrevious(usize, usize),
28-
#[error("{}: invalid pattern", ._0.quote())]
30+
#[error("{}", get_message_with_args("csplit-error-invalid-pattern", HashMap::from([("pattern".to_string(), _0.quote().to_string())])))]
2931
InvalidPattern(String),
30-
#[error("invalid number: {}", ._0.quote())]
32+
#[error("{}", get_message_with_args("csplit-error-invalid-number", HashMap::from([("number".to_string(), _0.quote().to_string())])))]
3133
InvalidNumber(String),
32-
#[error("incorrect conversion specification in suffix")]
34+
#[error("{}", get_message("csplit-error-suffix-format-incorrect"))]
3335
SuffixFormatIncorrect,
34-
#[error("too many % conversion specifications in suffix")]
36+
#[error("{}", get_message("csplit-error-suffix-format-too-many-percents"))]
3537
SuffixFormatTooManyPercents,
36-
#[error("{} is not a regular file", ._0.quote())]
38+
#[error("{}", get_message_with_args("csplit-error-not-regular-file", HashMap::from([("file".to_string(), _0.quote().to_string())])))]
3739
NotRegularFile(String),
3840
#[error("{}", _0)]
3941
UError(Box<dyn UError>),

src/uu/csplit/src/patterns.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use crate::csplit_error::CsplitError;
88
use regex::Regex;
9+
use std::collections::HashMap;
10+
use uucore::locale::get_message_with_args;
911
use uucore::show_warning;
1012

1113
/// The definition of a pattern to match on a line.
@@ -168,7 +170,13 @@ fn validate_line_numbers(patterns: &[Pattern]) -> Result<(), CsplitError> {
168170
(_, 0) => Err(CsplitError::LineNumberIsZero),
169171
// two consecutive numbers should not be equal
170172
(n, m) if n == m => {
171-
show_warning!("line number '{n}' is the same as preceding line number");
173+
show_warning!(
174+
"{}",
175+
get_message_with_args(
176+
"csplit-warning-line-number-same-as-previous",
177+
HashMap::from([("line_number".to_string(), n.to_string())])
178+
)
179+
);
172180
Ok(n)
173181
}
174182
// a number cannot be greater than the one that follows

0 commit comments

Comments
 (0)
0