Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/uu/numfmt/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,41 @@ numfmt-after-help = UNIT options:
Optional width value (%10f) will pad output. Optional zero (%010f) width
will zero pad the number. Optional negative values (%-10f) will left align.
Optional precision (%.1f) will override the input determined precision.

# Help messages
numfmt-help-delimiter = use X instead of whitespace for field delimiter
numfmt-help-field = replace the numbers in these input fields; see FIELDS below
numfmt-help-format = use printf style floating-point FORMAT; see FORMAT below for details
numfmt-help-from = auto-scale input numbers to UNITs; see UNIT below
numfmt-help-from-unit = specify the input unit size
numfmt-help-to = auto-scale output numbers to UNITs; see UNIT below
numfmt-help-to-unit = the output unit size
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
numfmt-help-header = print (without converting) the first N header lines; N defaults to 1 if not specified
numfmt-help-round = use METHOD for rounding when scaling
numfmt-help-suffix = print SUFFIX after each formatted number, and accept inputs optionally ending with SUFFIX
numfmt-help-invalid = set the failure mode for invalid input
numfmt-help-zero-terminated = line delimiter is NUL, not newline

# Error messages
numfmt-error-unsupported-unit = Unsupported unit is specified
numfmt-error-invalid-unit-size = invalid unit size: { $size }
numfmt-error-invalid-padding = invalid padding value { $value }
numfmt-error-invalid-header = invalid header value { $value }
numfmt-error-grouping-cannot-be-combined-with-to = grouping cannot be combined with --to
numfmt-error-delimiter-must-be-single-character = the delimiter must be a single character
numfmt-error-invalid-number-empty = invalid number: ''
numfmt-error-invalid-suffix = invalid suffix in input: { $input }
numfmt-error-invalid-number = invalid number: { $input }
numfmt-error-missing-i-suffix = missing 'i' suffix in input: '{ $number }{ $suffix }' (e.g Ki/Mi/Gi)
numfmt-error-rejecting-suffix = rejecting suffix in input: '{ $number }{ $suffix }' (consider using --from)
numfmt-error-suffix-unsupported-for-unit = This suffix is unsupported for specified unit
numfmt-error-unit-auto-not-supported-with-to = Unit 'auto' isn't supported with --to options
numfmt-error-number-too-big = Number is too big and unsupported
numfmt-error-format-no-percent = format '{ $format }' has no % directive
numfmt-error-format-ends-in-percent = format '{ $format }' ends in %
numfmt-error-invalid-format-directive = invalid format '{ $format }', directive must be %[0]['][-][N][.][N]f
numfmt-error-invalid-format-width-overflow = invalid format '{ $format }' (width overflow)
numfmt-error-invalid-precision = invalid precision in format '{ $format }'
numfmt-error-format-too-many-percent = format '{ $format }' has too many % directives
numfmt-error-unknown-invalid-mode = Unknown invalid mode: { $mode }
74 changes: 74 additions & 0 deletions src/uu/numfmt/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
numfmt-about = Convertir les nombres vers/depuis des chaînes lisibles par l'homme
numfmt-usage = numfmt [OPTION]... [NOMBRE]...
numfmt-after-help = Options d'UNITÉ :

- none : aucune mise à l'échelle automatique n'est effectuée ; les suffixes déclencheront une erreur
- auto : accepter un suffixe optionnel d'une/deux lettres :

1K = 1000, 1Ki = 1024, 1M = 1000000, 1Mi = 1048576,

- si : accepter un suffixe optionnel d'une lettre :

1K = 1000, 1M = 1000000, ...

- iec : accepter un suffixe optionnel d'une lettre :

1K = 1024, 1M = 1048576, ...

- iec-i : accepter un suffixe optionnel de deux lettres :

1Ki = 1024, 1Mi = 1048576, ...

- FIELDS supporte les plages de champs de style cut(1) :

N N-ième champ, compté à partir de 1
N- du N-ième champ jusqu'à la fin de la ligne
N-M du N-ième au M-ième champ (inclus)
-M du premier au M-ième champ (inclus)
- tous les champs

Plusieurs champs/plages peuvent être séparés par des virgules

FORMAT doit être adapté pour imprimer un argument à virgule flottante %f.
Une guillemet optionnelle (%'f) activera --grouping (si supporté par la locale actuelle).
Une valeur de largeur optionnelle (%10f) remplira la sortie. Un zéro optionnel (%010f)
remplira le nombre de zéros. Des valeurs négatives optionnelles (%-10f) aligneront à gauche.
Une précision optionnelle (%.1f) remplacera la précision déterminée par l'entrée.

# Messages d'aide
numfmt-help-delimiter = utiliser X au lieu d'espaces pour le délimiteur de champ
numfmt-help-field = remplacer les nombres dans ces champs d'entrée ; voir FIELDS ci-dessous
numfmt-help-format = utiliser le FORMAT à virgule flottante de style printf ; voir FORMAT ci-dessous pour les détails
numfmt-help-from = mettre automatiquement à l'échelle les nombres d'entrée vers les UNITÉs ; voir UNIT ci-dessous
numfmt-help-from-unit = spécifier la taille de l'unité d'entrée
numfmt-help-to = mettre automatiquement à l'échelle les nombres de sortie vers les UNITÉs ; voir UNIT ci-dessous
numfmt-help-to-unit = la taille de l'unité de sortie
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é
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é
numfmt-help-round = utiliser METHOD pour l'arrondi lors de la mise à l'échelle
numfmt-help-suffix = imprimer SUFFIX après chaque nombre formaté, et accepter les entrées se terminant optionnellement par SUFFIX
numfmt-help-invalid = définir le mode d'échec pour les entrées invalides
numfmt-help-zero-terminated = le délimiteur de ligne est NUL, pas retour à la ligne

# Messages d'erreur
numfmt-error-unsupported-unit = Une unité non supportée est spécifiée
numfmt-error-invalid-unit-size = taille d'unité invalide : { $size }
numfmt-error-invalid-padding = valeur de remplissage invalide { $value }
numfmt-error-invalid-header = valeur d'en-tête invalide { $value }
numfmt-error-grouping-cannot-be-combined-with-to = le groupement ne peut pas être combiné avec --to
numfmt-error-delimiter-must-be-single-character = le délimiteur doit être un seul caractère
numfmt-error-invalid-number-empty = nombre invalide : ''
numfmt-error-invalid-suffix = suffixe invalide dans l'entrée : { $input }
numfmt-error-invalid-number = nombre invalide : { $input }
numfmt-error-missing-i-suffix = suffixe 'i' manquant dans l'entrée : '{ $number }{ $suffix }' (par ex. Ki/Mi/Gi)
numfmt-error-rejecting-suffix = rejet du suffixe dans l'entrée : '{ $number }{ $suffix }' (considérez utiliser --from)
numfmt-error-suffix-unsupported-for-unit = Ce suffixe n'est pas supporté pour l'unité spécifiée
numfmt-error-unit-auto-not-supported-with-to = L'unité 'auto' n'est pas supportée avec les options --to
numfmt-error-number-too-big = Le nombre est trop grand et non supporté
numfmt-error-format-no-percent = le format '{ $format }' n'a pas de directive %
numfmt-error-format-ends-in-percent = le format '{ $format }' se termine par %
numfmt-error-invalid-format-directive = format invalide '{ $format }', la directive doit être %[0]['][-][N][.][N]f
numfmt-error-invalid-format-width-overflow = format invalide '{ $format }' (débordement de largeur)
numfmt-error-invalid-precision = précision invalide dans le format '{ $format }'
numfmt-error-format-too-many-percent = le format '{ $format }' a trop de directives %
numfmt-error-unknown-invalid-mode = Mode invalide inconnu : { $mode }
46 changes: 33 additions & 13 deletions src/uu/numfmt/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore powf
use std::collections::HashMap;
use uucore::display::Quotable;
use uucore::locale::{get_message, get_message_with_args};

use crate::options::{NumfmtOptions, RoundMethod, TransformOptions};
use crate::units::{DisplayableSuffix, IEC_BASES, RawSuffix, Result, SI_BASES, Suffix, Unit};
Expand Down Expand Up @@ -63,7 +65,7 @@

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

let with_i = s.ends_with('i');
Expand All @@ -81,7 +83,12 @@
Some('Z') => Some((RawSuffix::Z, with_i)),
Some('Y') => Some((RawSuffix::Y, with_i)),
Some('0'..='9') if !with_i => None,
_ => return Err(format!("invalid suffix in input: {}", s.quote())),
_ => {
return Err(get_message_with_args(
"numfmt-error-invalid-suffix",
HashMap::from([("input".to_string(), s.quote().to_string())]),
));
}
};

let suffix_len = match suffix {
Expand All @@ -90,9 +97,12 @@
Some((_, true)) => 2,
};

let number = s[..s.len() - suffix_len]
.parse::<f64>()
.map_err(|_| format!("invalid number: {}", s.quote()))?;
let number = s[..s.len() - suffix_len].parse::<f64>().map_err(|_| {
get_message_with_args(
"numfmt-error-invalid-number",
HashMap::from([("input".to_string(), s.quote().to_string())]),
)
})?;

Ok((number, suffix))
}
Expand Down Expand Up @@ -132,15 +142,25 @@
RawSuffix::Z => Ok(i * IEC_BASES[7]),
RawSuffix::Y => Ok(i * IEC_BASES[8]),
},
(Some((raw_suffix, false)), &Unit::Iec(true)) => Err(format!(
"missing 'i' suffix in input: '{i}{raw_suffix:?}' (e.g Ki/Mi/Gi)"
(Some((raw_suffix, false)), &Unit::Iec(true)) => Err(get_message_with_args(
"numfmt-error-missing-i-suffix",
HashMap::from([
("number".to_string(), i.to_string()),
("suffix".to_string(), format!("{raw_suffix:?}")),
]),
)),
(Some((raw_suffix, with_i)), &Unit::None) => Err(format!(
"rejecting suffix in input: '{i}{raw_suffix:?}{}' (consider using --from)",
if with_i { "i" } else { "" }
(Some((raw_suffix, with_i)), &Unit::None) => Err(get_message_with_args(
"numfmt-error-rejecting-suffix",
HashMap::from([
("number".to_string(), i.to_string()),
(
"suffix".to_string(),
format!("{raw_suffix:?}{}", if with_i { "i" } else { "" }),
),
]),
)),
(None, _) => Ok(i),
(_, _) => Err("This suffix is unsupported for specified unit".to_owned()),
(_, _) => Err(get_message("numfmt-error-suffix-unsupported-for-unit")),

Check warning on line 163 in src/uu/numfmt/src/format.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/numfmt/src/format.rs#L163

Added line #L163 was not covered by tests
}
}

Expand Down Expand Up @@ -218,7 +238,7 @@
let (bases, with_i) = match *u {
Unit::Si => (&SI_BASES, false),
Unit::Iec(with_i) => (&IEC_BASES, with_i),
Unit::Auto => return Err("Unit 'auto' isn't supported with --to options".to_owned()),
Unit::Auto => return Err(get_message("numfmt-error-unit-auto-not-supported-with-to")),

Check warning on line 241 in src/uu/numfmt/src/format.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/numfmt/src/format.rs#L241

Added line #L241 was not covered by tests
Unit::None => return Ok((n, None)),
};

Expand All @@ -232,7 +252,7 @@
_ if abs_n < bases[7] => 6,
_ if abs_n < bases[8] => 7,
_ if abs_n < bases[9] => 8,
_ => return Err("Number is too big and unsupported".to_string()),
_ => return Err(get_message("numfmt-error-number-too-big")),

Check warning on line 255 in src/uu/numfmt/src/format.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/numfmt/src/format.rs#L255

Added line #L255 was not covered by tests
};

let v = if precision > 0 {
Expand Down
Loading
Loading