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

Skip to content

Commit b41f54c

Browse files
authored
Merge pull request #8208 from sylvestre/l10n-numfmt
l10n: port numfmt for translation + add french
2 parents 6275e62 + 6aa4e6d commit b41f54c

File tree

5 files changed

+221
-57
lines changed

5 files changed

+221
-57
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,41 @@ numfmt-after-help = UNIT options:
3434
Optional width value (%10f) will pad output. Optional zero (%010f) width
3535
will zero pad the number. Optional negative values (%-10f) will left align.
3636
Optional precision (%.1f) will override the input determined precision.
37+
38+
# Help messages
39+
numfmt-help-delimiter = use X instead of whitespace for field delimiter
40+
numfmt-help-field = replace the numbers in these input fields; see FIELDS below
41+
numfmt-help-format = use printf style floating-point FORMAT; see FORMAT below for details
42+
numfmt-help-from = auto-scale input numbers to UNITs; see UNIT below
43+
numfmt-help-from-unit = specify the input unit size
44+
numfmt-help-to = auto-scale output numbers to UNITs; see UNIT below
45+
numfmt-help-to-unit = the output unit size
46+
numfmt-help-padding = pad the output to N characters; positive N will right-align; negative N will left-align; padding is ignored if the output is wider than N; the default is to automatically pad if a whitespace is found
47+
numfmt-help-header = print (without converting) the first N header lines; N defaults to 1 if not specified
48+
numfmt-help-round = use METHOD for rounding when scaling
49+
numfmt-help-suffix = print SUFFIX after each formatted number, and accept inputs optionally ending with SUFFIX
50+
numfmt-help-invalid = set the failure mode for invalid input
51+
numfmt-help-zero-terminated = line delimiter is NUL, not newline
52+
53+
# Error messages
54+
numfmt-error-unsupported-unit = Unsupported unit is specified
55+
numfmt-error-invalid-unit-size = invalid unit size: { $size }
56+
numfmt-error-invalid-padding = invalid padding value { $value }
57+
numfmt-error-invalid-header = invalid header value { $value }
58+
numfmt-error-grouping-cannot-be-combined-with-to = grouping cannot be combined with --to
59+
numfmt-error-delimiter-must-be-single-character = the delimiter must be a single character
60+
numfmt-error-invalid-number-empty = invalid number: ''
61+
numfmt-error-invalid-suffix = invalid suffix in input: { $input }
62+
numfmt-error-invalid-number = invalid number: { $input }
63+
numfmt-error-missing-i-suffix = missing 'i' suffix in input: '{ $number }{ $suffix }' (e.g Ki/Mi/Gi)
64+
numfmt-error-rejecting-suffix = rejecting suffix in input: '{ $number }{ $suffix }' (consider using --from)
65+
numfmt-error-suffix-unsupported-for-unit = This suffix is unsupported for specified unit
66+
numfmt-error-unit-auto-not-supported-with-to = Unit 'auto' isn't supported with --to options
67+
numfmt-error-number-too-big = Number is too big and unsupported
68+
numfmt-error-format-no-percent = format '{ $format }' has no % directive
69+
numfmt-error-format-ends-in-percent = format '{ $format }' ends in %
70+
numfmt-error-invalid-format-directive = invalid format '{ $format }', directive must be %[0]['][-][N][.][N]f
71+
numfmt-error-invalid-format-width-overflow = invalid format '{ $format }' (width overflow)
72+
numfmt-error-invalid-precision = invalid precision in format '{ $format }'
73+
numfmt-error-format-too-many-percent = format '{ $format }' has too many % directives
74+
numfmt-error-unknown-invalid-mode = Unknown invalid mode: { $mode }

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
numfmt-about = Convertir les nombres vers/depuis des chaînes lisibles par l'homme
2+
numfmt-usage = numfmt [OPTION]... [NOMBRE]...
3+
numfmt-after-help = Options d'UNITÉ :
4+
5+
- none : aucune mise à l'échelle automatique n'est effectuée ; les suffixes déclencheront une erreur
6+
- auto : accepter un suffixe optionnel d'une/deux lettres :
7+
8+
1K = 1000, 1Ki = 1024, 1M = 1000000, 1Mi = 1048576,
9+
10+
- si : accepter un suffixe optionnel d'une lettre :
11+
12+
1K = 1000, 1M = 1000000, ...
13+
14+
- iec : accepter un suffixe optionnel d'une lettre :
15+
16+
1K = 1024, 1M = 1048576, ...
17+
18+
- iec-i : accepter un suffixe optionnel de deux lettres :
19+
20+
1Ki = 1024, 1Mi = 1048576, ...
21+
22+
- FIELDS supporte les plages de champs de style cut(1) :
23+
24+
N N-ième champ, compté à partir de 1
25+
N- du N-ième champ jusqu'à la fin de la ligne
26+
N-M du N-ième au M-ième champ (inclus)
27+
-M du premier au M-ième champ (inclus)
28+
- tous les champs
29+
30+
Plusieurs champs/plages peuvent être séparés par des virgules
31+
32+
FORMAT doit être adapté pour imprimer un argument à virgule flottante %f.
33+
Une guillemet optionnelle (%'f) activera --grouping (si supporté par la locale actuelle).
34+
Une valeur de largeur optionnelle (%10f) remplira la sortie. Un zéro optionnel (%010f)
35+
remplira le nombre de zéros. Des valeurs négatives optionnelles (%-10f) aligneront à gauche.
36+
Une précision optionnelle (%.1f) remplacera la précision déterminée par l'entrée.
37+
38+
# Messages d'aide
39+
numfmt-help-delimiter = utiliser X au lieu d'espaces pour le délimiteur de champ
40+
numfmt-help-field = remplacer les nombres dans ces champs d'entrée ; voir FIELDS ci-dessous
41+
numfmt-help-format = utiliser le FORMAT à virgule flottante de style printf ; voir FORMAT ci-dessous pour les détails
42+
numfmt-help-from = mettre automatiquement à l'échelle les nombres d'entrée vers les UNITÉs ; voir UNIT ci-dessous
43+
numfmt-help-from-unit = spécifier la taille de l'unité d'entrée
44+
numfmt-help-to = mettre automatiquement à l'échelle les nombres de sortie vers les UNITÉs ; voir UNIT ci-dessous
45+
numfmt-help-to-unit = la taille de l'unité de sortie
46+
numfmt-help-padding = remplir la sortie à N caractères ; N positif alignera à droite ; N négatif alignera à gauche ; le remplissage est ignoré si la sortie est plus large que N ; la valeur par défaut est de remplir automatiquement si un espace est trouvé
47+
numfmt-help-header = imprimer (sans convertir) les N premières lignes d'en-tête ; N vaut 1 par défaut si non spécifié
48+
numfmt-help-round = utiliser METHOD pour l'arrondi lors de la mise à l'échelle
49+
numfmt-help-suffix = imprimer SUFFIX après chaque nombre formaté, et accepter les entrées se terminant optionnellement par SUFFIX
50+
numfmt-help-invalid = définir le mode d'échec pour les entrées invalides
51+
numfmt-help-zero-terminated = le délimiteur de ligne est NUL, pas retour à la ligne
52+
53+
# Messages d'erreur
54+
numfmt-error-unsupported-unit = Une unité non supportée est spécifiée
55+
numfmt-error-invalid-unit-size = taille d'unité invalide : { $size }
56+
numfmt-error-invalid-padding = valeur de remplissage invalide { $value }
57+
numfmt-error-invalid-header = valeur d'en-tête invalide { $value }
58+
numfmt-error-grouping-cannot-be-combined-with-to = le groupement ne peut pas être combiné avec --to
59+
numfmt-error-delimiter-must-be-single-character = le délimiteur doit être un seul caractère
60+
numfmt-error-invalid-number-empty = nombre invalide : ''
61+
numfmt-error-invalid-suffix = suffixe invalide dans l'entrée : { $input }
62+
numfmt-error-invalid-number = nombre invalide : { $input }
63+
numfmt-error-missing-i-suffix = suffixe 'i' manquant dans l'entrée : '{ $number }{ $suffix }' (par ex. Ki/Mi/Gi)
64+
numfmt-error-rejecting-suffix = rejet du suffixe dans l'entrée : '{ $number }{ $suffix }' (considérez utiliser --from)
65+
numfmt-error-suffix-unsupported-for-unit = Ce suffixe n'est pas supporté pour l'unité spécifiée
66+
numfmt-error-unit-auto-not-supported-with-to = L'unité 'auto' n'est pas supportée avec les options --to
67+
numfmt-error-number-too-big = Le nombre est trop grand et non supporté
68+
numfmt-error-format-no-percent = le format '{ $format }' n'a pas de directive %
69+
numfmt-error-format-ends-in-percent = le format '{ $format }' se termine par %
70+
numfmt-error-invalid-format-directive = format invalide '{ $format }', la directive doit être %[0]['][-][N][.][N]f
71+
numfmt-error-invalid-format-width-overflow = format invalide '{ $format }' (débordement de largeur)
72+
numfmt-error-invalid-precision = précision invalide dans le format '{ $format }'
73+
numfmt-error-format-too-many-percent = le format '{ $format }' a trop de directives %
74+
numfmt-error-unknown-invalid-mode = Mode invalide inconnu : { $mode }

src/uu/numfmt/src/format.rs

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55
// spell-checker:ignore powf
6+
use std::collections::HashMap;
67
use uucore::display::Quotable;
8+
use uucore::locale::{get_message, get_message_with_args};
79

810
use crate::options::{NumfmtOptions, RoundMethod, TransformOptions};
911
use crate::units::{DisplayableSuffix, IEC_BASES, RawSuffix, Result, SI_BASES, Suffix, Unit};
@@ -63,7 +65,7 @@ impl<'a> Iterator for WhitespaceSplitter<'a> {
6365

6466
fn parse_suffix(s: &str) -> Result<(f64, Option<Suffix>)> {
6567
if s.is_empty() {
66-
return Err("invalid number: ''".to_string());
68+
return Err(get_message("numfmt-error-invalid-number-empty"));
6769
}
6870

6971
let with_i = s.ends_with('i');
@@ -81,7 +83,12 @@ fn parse_suffix(s: &str) -> Result<(f64, Option<Suffix>)> {
8183
Some('Z') => Some((RawSuffix::Z, with_i)),
8284
Some('Y') => Some((RawSuffix::Y, with_i)),
8385
Some('0'..='9') if !with_i => None,
84-
_ => return Err(format!("invalid suffix in input: {}", s.quote())),
86+
_ => {
87+
return Err(get_message_with_args(
88+
"numfmt-error-invalid-suffix",
89+
HashMap::from([("input".to_string(), s.quote().to_string())]),
90+
));
91+
}
8592
};
8693

8794
let suffix_len = match suffix {
@@ -90,9 +97,12 @@ fn parse_suffix(s: &str) -> Result<(f64, Option<Suffix>)> {
9097
Some((_, true)) => 2,
9198
};
9299

93-
let number = s[..s.len() - suffix_len]
94-
.parse::<f64>()
95-
.map_err(|_| format!("invalid number: {}", s.quote()))?;
100+
let number = s[..s.len() - suffix_len].parse::<f64>().map_err(|_| {
101+
get_message_with_args(
102+
"numfmt-error-invalid-number",
103+
HashMap::from([("input".to_string(), s.quote().to_string())]),
104+
)
105+
})?;
96106

97107
Ok((number, suffix))
98108
}
@@ -132,15 +142,25 @@ fn remove_suffix(i: f64, s: Option<Suffix>, u: &Unit) -> Result<f64> {
132142
RawSuffix::Z => Ok(i * IEC_BASES[7]),
133143
RawSuffix::Y => Ok(i * IEC_BASES[8]),
134144
},
135-
(Some((raw_suffix, false)), &Unit::Iec(true)) => Err(format!(
136-
"missing 'i' suffix in input: '{i}{raw_suffix:?}' (e.g Ki/Mi/Gi)"
145+
(Some((raw_suffix, false)), &Unit::Iec(true)) => Err(get_message_with_args(
146+
"numfmt-error-missing-i-suffix",
147+
HashMap::from([
148+
("number".to_string(), i.to_string()),
149+
("suffix".to_string(), format!("{raw_suffix:?}")),
150+
]),
137151
)),
138-
(Some((raw_suffix, with_i)), &Unit::None) => Err(format!(
139-
"rejecting suffix in input: '{i}{raw_suffix:?}{}' (consider using --from)",
140-
if with_i { "i" } else { "" }
152+
(Some((raw_suffix, with_i)), &Unit::None) => Err(get_message_with_args(
153+
"numfmt-error-rejecting-suffix",
154+
HashMap::from([
155+
("number".to_string(), i.to_string()),
156+
(
157+
"suffix".to_string(),
158+
format!("{raw_suffix:?}{}", if with_i { "i" } else { "" }),
159+
),
160+
]),
141161
)),
142162
(None, _) => Ok(i),
143-
(_, _) => Err("This suffix is unsupported for specified unit".to_owned()),
163+
(_, _) => Err(get_message("numfmt-error-suffix-unsupported-for-unit")),
144164
}
145165
}
146166

@@ -218,7 +238,7 @@ fn consider_suffix(
218238
let (bases, with_i) = match *u {
219239
Unit::Si => (&SI_BASES, false),
220240
Unit::Iec(with_i) => (&IEC_BASES, with_i),
221-
Unit::Auto => return Err("Unit 'auto' isn't supported with --to options".to_owned()),
241+
Unit::Auto => return Err(get_message("numfmt-error-unit-auto-not-supported-with-to")),
222242
Unit::None => return Ok((n, None)),
223243
};
224244

@@ -232,7 +252,7 @@ fn consider_suffix(
232252
_ if abs_n < bases[7] => 6,
233253
_ if abs_n < bases[8] => 7,
234254
_ if abs_n < bases[9] => 8,
235-
_ => return Err("Number is too big and unsupported".to_string()),
255+
_ => return Err(get_message("numfmt-error-number-too-big")),
236256
};
237257

238258
let v = if precision > 0 {

0 commit comments

Comments
 (0)
0