1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

Merge pull request #8148 from sylvestre/l10n-cksum

l10n: port cksum for translation + add french
This commit is contained in:
Daniel Hofstetter 2025-06-11 11:03:14 +02:00 committed by GitHub
commit 316466b9d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 78 additions and 25 deletions

View file

@ -14,3 +14,22 @@ cksum-after-help = DIGEST determines the digest algorithm and default output for
- sha512: (equivalent to sha512sum) - sha512: (equivalent to sha512sum)
- blake2b: (equivalent to b2sum) - blake2b: (equivalent to b2sum)
- sm3: (only available through cksum) - sm3: (only available through cksum)
# Help messages
cksum-help-algorithm = select the digest type to use. See DIGEST below
cksum-help-untagged = create a reversed style checksum, without digest type
cksum-help-tag = create a BSD style checksum, undo --untagged (default)
cksum-help-length = digest length in bits; must not exceed the max for the blake2 algorithm and must be a multiple of 8
cksum-help-raw = emit a raw binary digest, not hexadecimal
cksum-help-strict = exit non-zero for improperly formatted checksum lines
cksum-help-check = read hashsums from the FILEs and check them
cksum-help-base64 = emit a base64 digest, not hexadecimal
cksum-help-warn = warn about improperly formatted checksum lines
cksum-help-status = don't output anything, status code shows success
cksum-help-quiet = don't print OK for each successfully verified file
cksum-help-ignore-missing = don't fail or report status for missing files
cksum-help-zero = end each output line with NUL, not newline, and disable file name escaping
# Error messages
cksum-error-is-directory = { $file }: Is a directory
cksum-error-failed-to-read-input = failed to read input

View file

@ -0,0 +1,35 @@
cksum-about = Afficher le CRC et la taille de chaque fichier
cksum-usage = cksum [OPTION]... [FICHIER]...
cksum-after-help = DIGEST détermine l'algorithme de condensé et le format de sortie par défaut :
- sysv : (équivalent à sum -s)
- bsd : (équivalent à sum -r)
- crc : (équivalent à cksum)
- crc32b : (disponible uniquement via cksum)
- md5 : (équivalent à md5sum)
- sha1 : (équivalent à sha1sum)
- sha224 : (équivalent à sha224sum)
- sha256 : (équivalent à sha256sum)
- sha384 : (équivalent à sha384sum)
- sha512 : (équivalent à sha512sum)
- blake2b : (équivalent à b2sum)
- sm3 : (disponible uniquement via cksum)
# Messages d'aide
cksum-help-algorithm = sélectionner le type de condensé à utiliser. Voir DIGEST ci-dessous
cksum-help-untagged = créer une somme de contrôle de style inversé, sans type de condensé
cksum-help-tag = créer une somme de contrôle de style BSD, annuler --untagged (par défaut)
cksum-help-length = longueur du condensé en bits ; ne doit pas dépasser le maximum pour l'algorithme blake2 et doit être un multiple de 8
cksum-help-raw = émettre un condensé binaire brut, pas hexadécimal
cksum-help-strict = sortir avec un code non-zéro pour les lignes de somme de contrôle mal formatées
cksum-help-check = lire les sommes de hachage des FICHIERs et les vérifier
cksum-help-base64 = émettre un condensé base64, pas hexadécimal
cksum-help-warn = avertir des lignes de somme de contrôle mal formatées
cksum-help-status = ne rien afficher, le code de statut indique le succès
cksum-help-quiet = ne pas afficher OK pour chaque fichier vérifié avec succès
cksum-help-ignore-missing = ne pas échouer ou signaler le statut pour les fichiers manquants
cksum-help-zero = terminer chaque ligne de sortie avec NUL, pas un saut de ligne, et désactiver l'échappement des noms de fichiers
# Messages d'erreur
cksum-error-is-directory = { $file } : Est un répertoire
cksum-error-failed-to-read-input = échec de la lecture de l'entrée

View file

@ -4,8 +4,10 @@
// file that was distributed with this source code. // file that was distributed with this source code.
// spell-checker:ignore (ToDO) fname, algo // spell-checker:ignore (ToDO) fname, algo
use clap::builder::ValueParser; use clap::builder::ValueParser;
use clap::{Arg, ArgAction, Command, value_parser}; use clap::{Arg, ArgAction, Command, value_parser};
use std::collections::HashMap;
use std::ffi::{OsStr, OsString}; use std::ffi::{OsStr, OsString};
use std::fs::File; use std::fs::File;
use std::io::{self, BufReader, Read, Write, stdin, stdout}; use std::io::{self, BufReader, Read, Write, stdin, stdout};
@ -17,7 +19,7 @@ use uucore::checksum::{
ChecksumVerbose, SUPPORTED_ALGORITHMS, calculate_blake2b_length, detect_algo, digest_reader, ChecksumVerbose, SUPPORTED_ALGORITHMS, calculate_blake2b_length, detect_algo, digest_reader,
perform_checksum_validation, perform_checksum_validation,
}; };
use uucore::locale::get_message; use uucore::locale::{get_message, get_message_with_args};
use uucore::{ use uucore::{
encoding, encoding,
error::{FromIo, UResult, USimpleError}, error::{FromIo, UResult, USimpleError},
@ -87,14 +89,17 @@ where
if filename.is_dir() { if filename.is_dir() {
show!(USimpleError::new( show!(USimpleError::new(
1, 1,
format!("{}: Is a directory", filename.display()) get_message_with_args(
"cksum-error-is-directory",
HashMap::from([("file".to_string(), filename.display().to_string())])
)
)); ));
continue; continue;
} }
let (sum_hex, sz) = let (sum_hex, sz) =
digest_reader(&mut options.digest, &mut file, false, options.output_bits) digest_reader(&mut options.digest, &mut file, false, options.output_bits)
.map_err_context(|| "failed to read input".to_string())?; .map_err_context(|| get_message("cksum-error-failed-to-read-input"))?;
let sum = match options.output_format { let sum = match options.output_format {
OutputFormat::Raw => { OutputFormat::Raw => {
@ -118,6 +123,7 @@ where
_ => encoding::for_cksum::BASE64.encode(&hex::decode(sum_hex).unwrap()), _ => encoding::for_cksum::BASE64.encode(&hex::decode(sum_hex).unwrap()),
}, },
}; };
// The BSD checksum output is 5 digit integer // The BSD checksum output is 5 digit integer
let bsd_width = 5; let bsd_width = 5;
let (before_filename, should_print_filename, after_filename) = match options.algo_name { let (before_filename, should_print_filename, after_filename) = match options.algo_name {
@ -171,6 +177,7 @@ where
} }
} }
}; };
print!("{before_filename}"); print!("{before_filename}");
if should_print_filename { if should_print_filename {
// The filename might not be valid UTF-8, and filename.display() would mangle the names. // The filename might not be valid UTF-8, and filename.display() would mangle the names.
@ -179,7 +186,6 @@ where
} }
print!("{after_filename}{}", options.line_ending); print!("{after_filename}{}", options.line_ending);
} }
Ok(()) Ok(())
} }
@ -279,6 +285,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
if tag || binary_flag || text_flag { if tag || binary_flag || text_flag {
return Err(ChecksumError::BinaryTextConflict.into()); return Err(ChecksumError::BinaryTextConflict.into());
} }
// Determine the appropriate algorithm option to pass // Determine the appropriate algorithm option to pass
let algo_option = if algo_name.is_empty() { let algo_option = if algo_name.is_empty() {
None None
@ -294,7 +301,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
); );
let verbose = ChecksumVerbose::new(status, quiet, warn); let verbose = ChecksumVerbose::new(status, quiet, warn);
let opts = ChecksumOptions { let opts = ChecksumOptions {
binary: binary_flag, binary: binary_flag,
ignore_missing, ignore_missing,
@ -355,21 +361,21 @@ pub fn uu_app() -> Command {
Arg::new(options::ALGORITHM) Arg::new(options::ALGORITHM)
.long(options::ALGORITHM) .long(options::ALGORITHM)
.short('a') .short('a')
.help("select the digest type to use. See DIGEST below") .help(get_message("cksum-help-algorithm"))
.value_name("ALGORITHM") .value_name("ALGORITHM")
.value_parser(SUPPORTED_ALGORITHMS), .value_parser(SUPPORTED_ALGORITHMS),
) )
.arg( .arg(
Arg::new(options::UNTAGGED) Arg::new(options::UNTAGGED)
.long(options::UNTAGGED) .long(options::UNTAGGED)
.help("create a reversed style checksum, without digest type") .help(get_message("cksum-help-untagged"))
.action(ArgAction::SetTrue) .action(ArgAction::SetTrue)
.overrides_with(options::TAG), .overrides_with(options::TAG),
) )
.arg( .arg(
Arg::new(options::TAG) Arg::new(options::TAG)
.long(options::TAG) .long(options::TAG)
.help("create a BSD style checksum, undo --untagged (default)") .help(get_message("cksum-help-tag"))
.action(ArgAction::SetTrue) .action(ArgAction::SetTrue)
.overrides_with(options::UNTAGGED), .overrides_with(options::UNTAGGED),
) )
@ -378,35 +384,32 @@ pub fn uu_app() -> Command {
.long(options::LENGTH) .long(options::LENGTH)
.value_parser(value_parser!(usize)) .value_parser(value_parser!(usize))
.short('l') .short('l')
.help( .help(get_message("cksum-help-length"))
"digest length in bits; must not exceed the max for the blake2 algorithm \
and must be a multiple of 8",
)
.action(ArgAction::Set), .action(ArgAction::Set),
) )
.arg( .arg(
Arg::new(options::RAW) Arg::new(options::RAW)
.long(options::RAW) .long(options::RAW)
.help("emit a raw binary digest, not hexadecimal") .help(get_message("cksum-help-raw"))
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::STRICT) Arg::new(options::STRICT)
.long(options::STRICT) .long(options::STRICT)
.help("exit non-zero for improperly formatted checksum lines") .help(get_message("cksum-help-strict"))
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::CHECK) Arg::new(options::CHECK)
.short('c') .short('c')
.long(options::CHECK) .long(options::CHECK)
.help("read hashsums from the FILEs and check them") .help(get_message("cksum-help-check"))
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::BASE64) Arg::new(options::BASE64)
.long(options::BASE64) .long(options::BASE64)
.help("emit a base64 digest, not hexadecimal") .help(get_message("cksum-help-base64"))
.action(ArgAction::SetTrue) .action(ArgAction::SetTrue)
// Even though this could easily just override an earlier '--raw', // Even though this could easily just override an earlier '--raw',
// GNU cksum does not permit these flags to be combined: // GNU cksum does not permit these flags to be combined:
@ -432,37 +435,35 @@ pub fn uu_app() -> Command {
Arg::new(options::WARN) Arg::new(options::WARN)
.short('w') .short('w')
.long("warn") .long("warn")
.help("warn about improperly formatted checksum lines") .help(get_message("cksum-help-warn"))
.action(ArgAction::SetTrue) .action(ArgAction::SetTrue)
.overrides_with_all([options::STATUS, options::QUIET]), .overrides_with_all([options::STATUS, options::QUIET]),
) )
.arg( .arg(
Arg::new(options::STATUS) Arg::new(options::STATUS)
.long("status") .long("status")
.help("don't output anything, status code shows success") .help(get_message("cksum-help-status"))
.action(ArgAction::SetTrue) .action(ArgAction::SetTrue)
.overrides_with_all([options::WARN, options::QUIET]), .overrides_with_all([options::WARN, options::QUIET]),
) )
.arg( .arg(
Arg::new(options::QUIET) Arg::new(options::QUIET)
.long(options::QUIET) .long(options::QUIET)
.help("don't print OK for each successfully verified file") .help(get_message("cksum-help-quiet"))
.action(ArgAction::SetTrue) .action(ArgAction::SetTrue)
.overrides_with_all([options::WARN, options::STATUS]), .overrides_with_all([options::WARN, options::STATUS]),
) )
.arg( .arg(
Arg::new(options::IGNORE_MISSING) Arg::new(options::IGNORE_MISSING)
.long(options::IGNORE_MISSING) .long(options::IGNORE_MISSING)
.help("don't fail or report status for missing files") .help(get_message("cksum-help-ignore-missing"))
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::ZERO) Arg::new(options::ZERO)
.long(options::ZERO) .long(options::ZERO)
.short('z') .short('z')
.help( .help(get_message("cksum-help-zero"))
"end each output line with NUL, not newline,\n and disable file name escaping",
)
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue),
) )
.after_help(get_message("cksum-after-help")) .after_help(get_message("cksum-after-help"))
@ -478,9 +479,7 @@ mod tests {
assert_eq!(calculate_blake2b_length(512).unwrap(), None); assert_eq!(calculate_blake2b_length(512).unwrap(), None);
assert_eq!(calculate_blake2b_length(256).unwrap(), Some(32)); assert_eq!(calculate_blake2b_length(256).unwrap(), Some(32));
calculate_blake2b_length(255).unwrap_err(); calculate_blake2b_length(255).unwrap_err();
calculate_blake2b_length(33).unwrap_err(); calculate_blake2b_length(33).unwrap_err();
calculate_blake2b_length(513).unwrap_err(); calculate_blake2b_length(513).unwrap_err();
} }
} }