Skip to content

Commit 63a3d6e

Browse files
committed
l10n: port mkdir to translation + add french
1 parent df0ef3b commit 63a3d6e

3 files changed

Lines changed: 67 additions & 17 deletions

File tree

src/uu/mkdir/locales/en-US.ftl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
mkdir-about = Create the given DIRECTORY(ies) if they do not exist
22
mkdir-usage = mkdir [OPTION]... DIRECTORY...
33
mkdir-after-help = Each MODE is of the form [ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+.
4+
5+
# Help messages
6+
mkdir-help-mode = set file mode (not implemented on windows)
7+
mkdir-help-parents = make parent directories as needed
8+
mkdir-help-verbose = print a message for each printed directory
9+
mkdir-help-selinux = set SELinux security context of each created directory to the default type
10+
mkdir-help-context = like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX
11+
12+
# Error messages
13+
mkdir-error-empty-directory-name = cannot create directory '': No such file or directory
14+
mkdir-error-file-exists = { $path }: File exists
15+
mkdir-error-failed-to-create-tree = failed to create whole tree
16+
mkdir-error-cannot-set-permissions = cannot set permissions { $path }
17+
18+
# Verbose output
19+
mkdir-verbose-created-directory = { $util_name }: created directory { $path }

src/uu/mkdir/locales/fr-FR.ftl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
mkdir-about = Créer les RÉPERTOIRE(s) donnés s'ils n'existent pas
2+
mkdir-usage = mkdir [OPTION]... RÉPERTOIRE...
3+
mkdir-after-help = Chaque MODE est de la forme [ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+.
4+
5+
# Messages d'aide
6+
mkdir-help-mode = définir le mode de fichier (non implémenté sur Windows)
7+
mkdir-help-parents = créer les répertoires parents si nécessaire
8+
mkdir-help-verbose = afficher un message pour chaque répertoire créé
9+
mkdir-help-selinux = définir le contexte de sécurité SELinux de chaque répertoire créé au type par défaut
10+
mkdir-help-context = comme -Z, ou si CTX est spécifié, définir le contexte de sécurité SELinux ou SMACK à CTX
11+
12+
# Messages d'erreur
13+
mkdir-error-empty-directory-name = impossible de créer le répertoire '' : Aucun fichier ou répertoire de ce type
14+
mkdir-error-file-exists = { $path } : Le fichier existe
15+
mkdir-error-failed-to-create-tree = échec de la création de l'arborescence complète
16+
mkdir-error-cannot-set-permissions = impossible de définir les permissions { $path }
17+
18+
# Sortie détaillée
19+
mkdir-verbose-created-directory = { $util_name } : répertoire créé { $path }

src/uu/mkdir/src/mkdir.rs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
use clap::builder::ValueParser;
99
use clap::parser::ValuesRef;
1010
use clap::{Arg, ArgAction, ArgMatches, Command};
11+
use std::collections::HashMap;
1112
use std::ffi::OsString;
1213
use std::path::{Path, PathBuf};
1314
#[cfg(not(windows))]
1415
use uucore::error::FromIo;
1516
use uucore::error::{UResult, USimpleError};
16-
use uucore::locale::get_message;
17+
use uucore::locale::{get_message, get_message_with_args};
1718
#[cfg(not(windows))]
1819
use uucore::mode;
1920
use uucore::{display::Quotable, fs::dir_strip_dot_for_creation};
@@ -139,32 +140,35 @@ pub fn uu_app() -> Command {
139140
Arg::new(options::MODE)
140141
.short('m')
141142
.long(options::MODE)
142-
.help("set file mode (not implemented on windows)"),
143+
.help(get_message("mkdir-help-mode")),
143144
)
144145
.arg(
145146
Arg::new(options::PARENTS)
146147
.short('p')
147148
.long(options::PARENTS)
148-
.help("make parent directories as needed")
149+
.help(get_message("mkdir-help-parents"))
149150
.overrides_with(options::PARENTS)
150151
.action(ArgAction::SetTrue),
151152
)
152153
.arg(
153154
Arg::new(options::VERBOSE)
154155
.short('v')
155156
.long(options::VERBOSE)
156-
.help("print a message for each printed directory")
157+
.help(get_message("mkdir-help-verbose"))
157158
.action(ArgAction::SetTrue),
158159
)
159160
.arg(
160161
Arg::new(options::SELINUX)
161162
.short('Z')
162-
.help("set SELinux security context of each created directory to the default type")
163+
.help(get_message("mkdir-help-selinux"))
163164
.action(ArgAction::SetTrue),
164165
)
165-
.arg(Arg::new(options::CONTEXT).long(options::CONTEXT).value_name("CTX").help(
166-
"like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX",
167-
))
166+
.arg(
167+
Arg::new(options::CONTEXT)
168+
.long(options::CONTEXT)
169+
.value_name("CTX")
170+
.help(get_message("mkdir-help-context")),
171+
)
168172
.arg(
169173
Arg::new(options::DIRS)
170174
.action(ArgAction::Append)
@@ -205,10 +209,9 @@ pub fn mkdir(path: &Path, config: &Config) -> UResult<()> {
205209
if path.as_os_str().is_empty() {
206210
return Err(USimpleError::new(
207211
1,
208-
"cannot create directory '': No such file or directory".to_owned(),
212+
get_message("mkdir-error-empty-directory-name"),
209213
));
210214
}
211-
212215
// Special case to match GNU's behavior:
213216
// mkdir -p foo/. should work and just create foo/
214217
// std::fs::create_dir("foo/."); fails in pure Rust
@@ -222,8 +225,12 @@ fn chmod(path: &Path, mode: u32) -> UResult<()> {
222225
use std::fs::{Permissions, set_permissions};
223226
use std::os::unix::fs::PermissionsExt;
224227
let mode = Permissions::from_mode(mode);
225-
set_permissions(path, mode)
226-
.map_err_context(|| format!("cannot set permissions {}", path.quote()))
228+
set_permissions(path, mode).map_err_context(|| {
229+
get_message_with_args(
230+
"mkdir-error-cannot-set-permissions",
231+
HashMap::from([("path".to_string(), path.quote().to_string())]),
232+
)
233+
})
227234
}
228235

229236
#[cfg(windows)]
@@ -240,7 +247,10 @@ fn create_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<()> {
240247
if path_exists && !config.recursive {
241248
return Err(USimpleError::new(
242249
1,
243-
format!("{}: File exists", path.display()),
250+
get_message_with_args(
251+
"mkdir-error-file-exists",
252+
HashMap::from([("path".to_string(), path.to_string_lossy().to_string())]),
253+
),
244254
));
245255
}
246256
if path == Path::new("") {
@@ -251,7 +261,7 @@ fn create_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<()> {
251261
match path.parent() {
252262
Some(p) => create_dir(p, true, config)?,
253263
None => {
254-
USimpleError::new(1, "failed to create whole tree");
264+
USimpleError::new(1, get_message("mkdir-error-failed-to-create-tree"));
255265
}
256266
}
257267
}
@@ -260,9 +270,14 @@ fn create_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<()> {
260270
Ok(()) => {
261271
if config.verbose {
262272
println!(
263-
"{}: created directory {}",
264-
uucore::util_name(),
265-
path.quote()
273+
"{}",
274+
get_message_with_args(
275+
"mkdir-verbose-created-directory",
276+
HashMap::from([
277+
("util_name".to_string(), uucore::util_name().to_string()),
278+
("path".to_string(), path.quote().to_string())
279+
])
280+
)
266281
);
267282
}
268283

0 commit comments

Comments
 (0)