diff --git a/src/uu/chown/locales/en-US.ftl b/src/uu/chown/locales/en-US.ftl index 4c8f2a46af3..0dfe8301e9d 100644 --- a/src/uu/chown/locales/en-US.ftl +++ b/src/uu/chown/locales/en-US.ftl @@ -1,3 +1,23 @@ chown-about = Change file owner and group chown-usage = chown [OPTION]... [OWNER][:[GROUP]] FILE... chown [OPTION]... --reference=RFILE FILE... + +# Help messages +chown-help-print-help = Print help information. +chown-help-changes = like verbose but report only when a change is made +chown-help-from = change the owner and/or group of each file only if its + current owner and/or group match those specified here. + Either may be omitted, in which case a match is not required + for the omitted attribute +chown-help-preserve-root = fail to operate recursively on '/' +chown-help-no-preserve-root = do not treat '/' specially (the default) +chown-help-quiet = suppress most error messages +chown-help-recursive = operate on files and directories recursively +chown-help-reference = use RFILE's owner and group rather than specifying OWNER:GROUP values +chown-help-verbose = output a diagnostic for every file processed + +# Error messages +chown-error-failed-to-get-attributes = failed to get attributes of { $file } +chown-error-invalid-user = invalid user: { $user } +chown-error-invalid-group = invalid group: { $group } +chown-error-invalid-spec = invalid spec: { $spec } diff --git a/src/uu/chown/locales/fr-FR.ftl b/src/uu/chown/locales/fr-FR.ftl new file mode 100644 index 00000000000..48e39853a3e --- /dev/null +++ b/src/uu/chown/locales/fr-FR.ftl @@ -0,0 +1,23 @@ +chown-about = Changer le propriétaire et le groupe des fichiers +chown-usage = chown [OPTION]... [PROPRIÉTAIRE][:[GROUPE]] FICHIER... + chown [OPTION]... --reference=RFICHIER FICHIER... + +# Messages d'aide +chown-help-print-help = Afficher les informations d'aide. +chown-help-changes = comme verbeux mais rapporter seulement lors d'un changement +chown-help-from = changer le propriétaire et/ou le groupe de chaque fichier seulement si son + propriétaire et/ou groupe actuel correspondent à ceux spécifiés ici. + L'un ou l'autre peut être omis, auquel cas une correspondance n'est pas requise + pour l'attribut omis +chown-help-preserve-root = échouer à opérer récursivement sur '/' +chown-help-no-preserve-root = ne pas traiter '/' spécialement (par défaut) +chown-help-quiet = supprimer la plupart des messages d'erreur +chown-help-recursive = opérer sur les fichiers et répertoires récursivement +chown-help-reference = utiliser le propriétaire et groupe de RFICHIER plutôt que spécifier les valeurs PROPRIÉTAIRE:GROUPE +chown-help-verbose = afficher un diagnostic pour chaque fichier traité + +# Messages d'erreur +chown-error-failed-to-get-attributes = échec de l'obtention des attributs de { $file } +chown-error-invalid-user = utilisateur invalide : { $user } +chown-error-invalid-group = groupe invalide : { $group } +chown-error-invalid-spec = spécification invalide : { $spec } diff --git a/src/uu/chown/src/chown.rs b/src/uu/chown/src/chown.rs index bf820c11ea3..24c97f92331 100644 --- a/src/uu/chown/src/chown.rs +++ b/src/uu/chown/src/chown.rs @@ -17,7 +17,8 @@ use clap::{Arg, ArgAction, ArgMatches, Command}; use std::fs; use std::os::unix::fs::MetadataExt; -use uucore::locale::get_message; +use std::collections::HashMap; +use uucore::locale::{get_message, get_message_with_args}; fn parse_gid_uid_and_filter(matches: &ArgMatches) -> UResult { let filter = if let Some(spec) = matches.get_one::(options::FROM) { @@ -35,8 +36,12 @@ fn parse_gid_uid_and_filter(matches: &ArgMatches) -> UResult let dest_gid: Option; let raw_owner: String; if let Some(file) = matches.get_one::(options::REFERENCE) { - let meta = fs::metadata(file) - .map_err_context(|| format!("failed to get attributes of {}", file.quote()))?; + let meta = fs::metadata(file).map_err_context(|| { + get_message_with_args( + "chown-error-failed-to-get-attributes", + HashMap::from([("file".to_string(), file.quote().to_string())]), + ) + })?; let gid = meta.gid(); let uid = meta.uid(); dest_gid = Some(gid); @@ -84,56 +89,51 @@ pub fn uu_app() -> Command { .arg( Arg::new(options::HELP) .long(options::HELP) - .help("Print help information.") + .help(get_message("chown-help-print-help")) .action(ArgAction::Help), ) .arg( Arg::new(options::verbosity::CHANGES) .short('c') .long(options::verbosity::CHANGES) - .help("like verbose but report only when a change is made") + .help(get_message("chown-help-changes")) .action(ArgAction::SetTrue), ) .arg( Arg::new(options::FROM) .long(options::FROM) - .help( - "change the owner and/or group of each file only if its \ - current owner and/or group match those specified here. \ - Either may be omitted, in which case a match is not required \ - for the omitted attribute", - ) + .help(get_message("chown-help-from")) .value_name("CURRENT_OWNER:CURRENT_GROUP"), ) .arg( Arg::new(options::preserve_root::PRESERVE) .long(options::preserve_root::PRESERVE) - .help("fail to operate recursively on '/'") + .help(get_message("chown-help-preserve-root")) .action(ArgAction::SetTrue), ) .arg( Arg::new(options::preserve_root::NO_PRESERVE) .long(options::preserve_root::NO_PRESERVE) - .help("do not treat '/' specially (the default)") + .help(get_message("chown-help-no-preserve-root")) .action(ArgAction::SetTrue), ) .arg( Arg::new(options::verbosity::QUIET) .long(options::verbosity::QUIET) - .help("suppress most error messages") + .help(get_message("chown-help-quiet")) .action(ArgAction::SetTrue), ) .arg( Arg::new(options::RECURSIVE) .short('R') .long(options::RECURSIVE) - .help("operate on files and directories recursively") + .help(get_message("chown-help-recursive")) .action(ArgAction::SetTrue), ) .arg( Arg::new(options::REFERENCE) .long(options::REFERENCE) - .help("use RFILE's owner and group rather than specifying OWNER:GROUP values") + .help(get_message("chown-help-reference")) .value_name("RFILE") .value_hint(clap::ValueHint::FilePath) .num_args(1..), @@ -148,7 +148,7 @@ pub fn uu_app() -> Command { Arg::new(options::verbosity::VERBOSE) .long(options::verbosity::VERBOSE) .short('v') - .help("output a diagnostic for every file processed") + .help(get_message("chown-help-verbose")) .action(ArgAction::SetTrue), ) // Add common arguments with chgrp, chown & chmod @@ -177,7 +177,10 @@ fn parse_uid(user: &str, spec: &str, sep: char) -> UResult> { Ok(uid) => Ok(Some(uid)), Err(_) => Err(USimpleError::new( 1, - format!("invalid user: {}", spec.quote()), + get_message_with_args( + "chown-error-invalid-user", + HashMap::from([("user".to_string(), spec.quote().to_string())]), + ), )), } } @@ -196,7 +199,10 @@ fn parse_gid(group: &str, spec: &str) -> UResult> { Ok(gid) => Ok(Some(gid)), Err(_) => Err(USimpleError::new( 1, - format!("invalid group: {}", spec.quote()), + get_message_with_args( + "chown-error-invalid-group", + HashMap::from([("group".to_string(), spec.quote().to_string())]), + ), )), }, } @@ -231,7 +237,10 @@ fn parse_spec(spec: &str, sep: char) -> UResult<(Option, Option)> { // we should fail with an error return Err(USimpleError::new( 1, - format!("invalid spec: {}", spec.quote()), + get_message_with_args( + "chown-error-invalid-spec", + HashMap::from([("spec".to_string(), spec.quote().to_string())]), + ), )); } @@ -241,9 +250,15 @@ fn parse_spec(spec: &str, sep: char) -> UResult<(Option, Option)> { #[cfg(test)] mod test { use super::*; + use std::env; + use uucore::locale; #[test] fn test_parse_spec() { + unsafe { + env::set_var("LANG", "C"); + } + let _ = locale::setup_localization("chown"); assert!(matches!(parse_spec(":", ':'), Ok((None, None)))); assert!(matches!(parse_spec(".", ':'), Ok((None, None)))); assert!(matches!(parse_spec(".", '.'), Ok((None, None))));