diff --git a/src/uu/basenc/locales/en-US.ftl b/src/uu/basenc/locales/en-US.ftl index 520292c85..a851acae9 100644 --- a/src/uu/basenc/locales/en-US.ftl +++ b/src/uu/basenc/locales/en-US.ftl @@ -5,3 +5,18 @@ basenc-about = Encode/decode data and print to standard output the formal alphabet. Use --ignore-garbage to attempt to recover from any other non-alphabet bytes in the encoded stream. basenc-usage = basenc [OPTION]... [FILE] + +# Help messages for encoding formats +basenc-help-base64 = same as 'base64' program +basenc-help-base64url = file- and url-safe base64 +basenc-help-base32 = same as 'base32' program +basenc-help-base32hex = extended hex alphabet base32 +basenc-help-base16 = hex encoding +basenc-help-base2lsbf = bit string with least significant bit (lsb) first +basenc-help-base2msbf = bit string with most significant bit (msb) first +basenc-help-z85 = ascii85-like encoding; + when encoding, input length must be a multiple of 4; + when decoding, input length must be a multiple of 5 + +# Error messages +basenc-error-missing-encoding-type = missing encoding type diff --git a/src/uu/basenc/locales/fr-FR.ftl b/src/uu/basenc/locales/fr-FR.ftl new file mode 100644 index 000000000..7bf87265f --- /dev/null +++ b/src/uu/basenc/locales/fr-FR.ftl @@ -0,0 +1,22 @@ +basenc-about = Encoder/décoder des données et afficher vers la sortie standard + Sans FICHIER, ou lorsque FICHIER est -, lire l'entrée standard. + + Lors du décodage, l'entrée peut contenir des nouvelles lignes en plus des octets de + l'alphabet formel. Utilisez --ignore-garbage pour tenter de récupérer + depuis tout autre octet non-alphabétique dans le flux encodé. +basenc-usage = basenc [OPTION]... [FICHIER] + +# Messages d'aide pour les formats d'encodage +basenc-help-base64 = identique au programme 'base64' +basenc-help-base64url = base64 sécurisé pour fichiers et URLs +basenc-help-base32 = identique au programme 'base32' +basenc-help-base32hex = base32 avec alphabet hexadécimal étendu +basenc-help-base16 = encodage hexadécimal +basenc-help-base2lsbf = chaîne de bits avec le bit de poids faible (lsb) en premier +basenc-help-base2msbf = chaîne de bits avec le bit de poids fort (msb) en premier +basenc-help-z85 = encodage de type ascii85 ; + lors de l'encodage, la longueur d'entrée doit être un multiple de 4 ; + lors du décodage, la longueur d'entrée doit être un multiple de 5 + +# Messages d'erreur +basenc-error-missing-encoding-type = type d'encodage manquant diff --git a/src/uu/basenc/src/basenc.rs b/src/uu/basenc/src/basenc.rs index 9da71e9de..d06ac3af7 100644 --- a/src/uu/basenc/src/basenc.rs +++ b/src/uu/basenc/src/basenc.rs @@ -13,46 +13,49 @@ use uucore::{ encoding::Format, error::{UResult, UUsageError}, }; -const ENCODINGS: &[(&str, Format, &str)] = &[ - ("base64", Format::Base64, "same as 'base64' program"), - ("base64url", Format::Base64Url, "file- and url-safe base64"), - ("base32", Format::Base32, "same as 'base32' program"), - ( - "base32hex", - Format::Base32Hex, - "extended hex alphabet base32", - ), - ("base16", Format::Base16, "hex encoding"), - ( - "base2lsbf", - Format::Base2Lsbf, - "bit string with least significant bit (lsb) first", - ), - ( - "base2msbf", - Format::Base2Msbf, - "bit string with most significant bit (msb) first", - ), - ( - "z85", - Format::Z85, - "ascii85-like encoding;\n\ - when encoding, input length must be a multiple of 4;\n\ - when decoding, input length must be a multiple of 5", - ), -]; + +fn get_encodings() -> Vec<(&'static str, Format, String)> { + vec![ + ("base64", Format::Base64, get_message("basenc-help-base64")), + ( + "base64url", + Format::Base64Url, + get_message("basenc-help-base64url"), + ), + ("base32", Format::Base32, get_message("basenc-help-base32")), + ( + "base32hex", + Format::Base32Hex, + get_message("basenc-help-base32hex"), + ), + ("base16", Format::Base16, get_message("basenc-help-base16")), + ( + "base2lsbf", + Format::Base2Lsbf, + get_message("basenc-help-base2lsbf"), + ), + ( + "base2msbf", + Format::Base2Msbf, + get_message("basenc-help-base2msbf"), + ), + ("z85", Format::Z85, get_message("basenc-help-z85")), + ] +} pub fn uu_app() -> Command { let about: &'static str = Box::leak(get_message("basenc-about").into_boxed_str()); let usage: &'static str = Box::leak(get_message("basenc-usage").into_boxed_str()); + let encodings = get_encodings(); let mut command = base_common::base_app(about, usage); - for encoding in ENCODINGS { + + for encoding in &encodings { let raw_arg = Arg::new(encoding.0) .long(encoding.0) - .help(encoding.2) + .help(&encoding.2) .action(ArgAction::SetTrue); - let overriding_arg = ENCODINGS + let overriding_arg = encodings .iter() .fold(raw_arg, |arg, enc| arg.overrides_with(enc.0)); command = command.arg(overriding_arg); @@ -64,10 +67,17 @@ fn parse_cmd_args(args: impl uucore::Args) -> UResult<(Config, Format)> { let matches = uu_app() .try_get_matches_from(args.collect_lossy()) .with_exit_code(1)?; - let format = ENCODINGS + + let encodings = get_encodings(); + let format = encodings .iter() .find(|encoding| matches.get_flag(encoding.0)) - .ok_or_else(|| UUsageError::new(BASE_CMD_PARSE_ERROR, "missing encoding type"))? + .ok_or_else(|| { + UUsageError::new( + BASE_CMD_PARSE_ERROR, + get_message("basenc-error-missing-encoding-type"), + ) + })? .1; let config = Config::from(&matches)?; Ok((config, format))