diff --git a/src/uu/mkdir/locales/en-US.ftl b/src/uu/mkdir/locales/en-US.ftl index 042329244..44fd5f5ad 100644 --- a/src/uu/mkdir/locales/en-US.ftl +++ b/src/uu/mkdir/locales/en-US.ftl @@ -1,3 +1,19 @@ mkdir-about = Create the given DIRECTORY(ies) if they do not exist mkdir-usage = mkdir [OPTION]... DIRECTORY... mkdir-after-help = Each MODE is of the form [ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+. + +# Help messages +mkdir-help-mode = set file mode (not implemented on windows) +mkdir-help-parents = make parent directories as needed +mkdir-help-verbose = print a message for each printed directory +mkdir-help-selinux = set SELinux security context of each created directory to the default type +mkdir-help-context = like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX + +# Error messages +mkdir-error-empty-directory-name = cannot create directory '': No such file or directory +mkdir-error-file-exists = { $path }: File exists +mkdir-error-failed-to-create-tree = failed to create whole tree +mkdir-error-cannot-set-permissions = cannot set permissions { $path } + +# Verbose output +mkdir-verbose-created-directory = { $util_name }: created directory { $path } diff --git a/src/uu/mkdir/locales/fr-FR.ftl b/src/uu/mkdir/locales/fr-FR.ftl new file mode 100644 index 000000000..d92bed965 --- /dev/null +++ b/src/uu/mkdir/locales/fr-FR.ftl @@ -0,0 +1,19 @@ +mkdir-about = Créer les RÉPERTOIRE(s) donnés s'ils n'existent pas +mkdir-usage = mkdir [OPTION]... RÉPERTOIRE... +mkdir-after-help = Chaque MODE est de la forme [ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+. + +# Messages d'aide +mkdir-help-mode = définir le mode de fichier (non implémenté sur Windows) +mkdir-help-parents = créer les répertoires parents si nécessaire +mkdir-help-verbose = afficher un message pour chaque répertoire créé +mkdir-help-selinux = définir le contexte de sécurité SELinux de chaque répertoire créé au type par défaut +mkdir-help-context = comme -Z, ou si CTX est spécifié, définir le contexte de sécurité SELinux ou SMACK à CTX + +# Messages d'erreur +mkdir-error-empty-directory-name = impossible de créer le répertoire '' : Aucun fichier ou répertoire de ce type +mkdir-error-file-exists = { $path } : Le fichier existe +mkdir-error-failed-to-create-tree = échec de la création de l'arborescence complète +mkdir-error-cannot-set-permissions = impossible de définir les permissions { $path } + +# Sortie détaillée +mkdir-verbose-created-directory = { $util_name } : répertoire créé { $path } diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index 7fceb36ce..7d41e4a14 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -8,12 +8,13 @@ use clap::builder::ValueParser; use clap::parser::ValuesRef; use clap::{Arg, ArgAction, ArgMatches, Command}; +use std::collections::HashMap; use std::ffi::OsString; use std::path::{Path, PathBuf}; #[cfg(not(windows))] use uucore::error::FromIo; use uucore::error::{UResult, USimpleError}; -use uucore::locale::get_message; +use uucore::locale::{get_message, get_message_with_args}; #[cfg(not(windows))] use uucore::mode; use uucore::{display::Quotable, fs::dir_strip_dot_for_creation}; @@ -139,13 +140,13 @@ pub fn uu_app() -> Command { Arg::new(options::MODE) .short('m') .long(options::MODE) - .help("set file mode (not implemented on windows)"), + .help(get_message("mkdir-help-mode")), ) .arg( Arg::new(options::PARENTS) .short('p') .long(options::PARENTS) - .help("make parent directories as needed") + .help(get_message("mkdir-help-parents")) .overrides_with(options::PARENTS) .action(ArgAction::SetTrue), ) @@ -153,18 +154,21 @@ pub fn uu_app() -> Command { Arg::new(options::VERBOSE) .short('v') .long(options::VERBOSE) - .help("print a message for each printed directory") + .help(get_message("mkdir-help-verbose")) .action(ArgAction::SetTrue), ) .arg( Arg::new(options::SELINUX) .short('Z') - .help("set SELinux security context of each created directory to the default type") + .help(get_message("mkdir-help-selinux")) .action(ArgAction::SetTrue), ) - .arg(Arg::new(options::CONTEXT).long(options::CONTEXT).value_name("CTX").help( - "like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX", - )) + .arg( + Arg::new(options::CONTEXT) + .long(options::CONTEXT) + .value_name("CTX") + .help(get_message("mkdir-help-context")), + ) .arg( Arg::new(options::DIRS) .action(ArgAction::Append) @@ -205,10 +209,9 @@ pub fn mkdir(path: &Path, config: &Config) -> UResult<()> { if path.as_os_str().is_empty() { return Err(USimpleError::new( 1, - "cannot create directory '': No such file or directory".to_owned(), + get_message("mkdir-error-empty-directory-name"), )); } - // Special case to match GNU's behavior: // mkdir -p foo/. should work and just create foo/ // std::fs::create_dir("foo/."); fails in pure Rust @@ -222,8 +225,12 @@ fn chmod(path: &Path, mode: u32) -> UResult<()> { use std::fs::{Permissions, set_permissions}; use std::os::unix::fs::PermissionsExt; let mode = Permissions::from_mode(mode); - set_permissions(path, mode) - .map_err_context(|| format!("cannot set permissions {}", path.quote())) + set_permissions(path, mode).map_err_context(|| { + get_message_with_args( + "mkdir-error-cannot-set-permissions", + HashMap::from([("path".to_string(), path.quote().to_string())]), + ) + }) } #[cfg(windows)] @@ -240,7 +247,10 @@ fn create_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<()> { if path_exists && !config.recursive { return Err(USimpleError::new( 1, - format!("{}: File exists", path.display()), + get_message_with_args( + "mkdir-error-file-exists", + HashMap::from([("path".to_string(), path.to_string_lossy().to_string())]), + ), )); } if path == Path::new("") { @@ -251,7 +261,7 @@ fn create_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<()> { match path.parent() { Some(p) => create_dir(p, true, config)?, None => { - USimpleError::new(1, "failed to create whole tree"); + USimpleError::new(1, get_message("mkdir-error-failed-to-create-tree")); } } } @@ -260,9 +270,14 @@ fn create_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<()> { Ok(()) => { if config.verbose { println!( - "{}: created directory {}", - uucore::util_name(), - path.quote() + "{}", + get_message_with_args( + "mkdir-verbose-created-directory", + HashMap::from([ + ("util_name".to_string(), uucore::util_name().to_string()), + ("path".to_string(), path.quote().to_string()) + ]) + ) ); }