Skip to content

Commit b2ef401

Browse files
committed
feat(rm): localize interactive prompt messages
1 parent 995c6dc commit b2ef401

4 files changed

Lines changed: 156 additions & 44 deletions

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,25 @@ rm-help-progress = display a progress bar. Note: this feature is not supported b
3333
# Progress messages
3434
rm-progress-removing = Removing
3535
36+
# Prompt messages
37+
rm-prompt-remove-arguments = remove { $count ->
38+
[one] { $count } argument?
39+
*[other] { $count } arguments?
40+
}
41+
rm-prompt-remove-arguments-recursive = remove { $count ->
42+
[one] { $count } argument recursively?
43+
*[other] { $count } arguments recursively?
44+
}
45+
rm-prompt-remove-symbolic-link = remove symbolic link { $file }?
46+
rm-prompt-remove-regular-empty-file = remove regular empty file { $file }?
47+
rm-prompt-remove-file = remove file { $file }?
48+
rm-prompt-remove-write-protected-regular-empty-file = remove write-protected regular empty file { $file }?
49+
rm-prompt-remove-write-protected-regular-file = remove write-protected regular file { $file }?
50+
rm-prompt-attempt-remove-inaccessible-directory = attempt removal of inaccessible directory { $path }?
51+
rm-prompt-remove-write-protected-directory = remove write-protected directory { $path }?
52+
rm-prompt-remove-directory = remove directory { $path }?
53+
rm-prompt-descend-into-directory = descend into directory { $path }?
54+
3655
# Error messages
3756
rm-error-missing-operand = missing operand
3857
Try '{$util_name} --help' for more information.

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,25 @@ rm-help-progress = afficher une barre de progression. Note : cette fonctionnalit
3333
# Messages de progression
3434
rm-progress-removing = Suppression
3535
36+
# Messages de confirmation
37+
rm-prompt-remove-arguments = supprimer { $count ->
38+
[one] { $count } argument ?
39+
*[other] { $count } arguments ?
40+
}
41+
rm-prompt-remove-arguments-recursive = supprimer { $count ->
42+
[one] { $count } argument récursivement ?
43+
*[other] { $count } arguments récursivement ?
44+
}
45+
rm-prompt-remove-symbolic-link = supprimer le lien symbolique { $file } ?
46+
rm-prompt-remove-regular-empty-file = supprimer le fichier ordinaire vide { $file } ?
47+
rm-prompt-remove-file = supprimer le fichier { $file } ?
48+
rm-prompt-remove-write-protected-regular-empty-file = supprimer le fichier ordinaire vide protégé en écriture { $file } ?
49+
rm-prompt-remove-write-protected-regular-file = supprimer le fichier ordinaire protégé en écriture { $file } ?
50+
rm-prompt-attempt-remove-inaccessible-directory = tenter de supprimer le répertoire inaccessible { $path } ?
51+
rm-prompt-remove-write-protected-directory = supprimer le répertoire protégé en écriture { $path } ?
52+
rm-prompt-remove-directory = supprimer le répertoire { $path } ?
53+
rm-prompt-descend-into-directory = descendre dans le répertoire { $path } ?
54+
3655
# Messages d'erreur
3756
rm-error-missing-operand = opérande manquant
3857
Essayez '{$util_name} --help' pour plus d'informations.

src/uu/rm/src/platform/unix.rs

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,22 @@ fn prompt_file_with_stat(path: &Path, stat: &libc::stat, options: &Options) -> b
5252
// otherwise fall through to protected wording.
5353
if options.interactive == InteractiveMode::Always {
5454
if is_symlink {
55-
return prompt_yes!("remove symbolic link {}?", path.quote());
55+
return prompt_yes!(
56+
"{}",
57+
translate!("rm-prompt-remove-symbolic-link", "file" => path.quote())
58+
);
5659
}
5760
if writable {
5861
return if len == 0 {
59-
prompt_yes!("remove regular empty file {}?", path.quote())
62+
prompt_yes!(
63+
"{}",
64+
translate!("rm-prompt-remove-regular-empty-file", "file" => path.quote())
65+
)
6066
} else {
61-
prompt_yes!("remove file {}?", path.quote())
67+
prompt_yes!(
68+
"{}",
69+
translate!("rm-prompt-remove-file", "file" => path.quote())
70+
)
6271
};
6372
}
6473
// Not writable: use protected wording below
@@ -69,10 +78,19 @@ fn prompt_file_with_stat(path: &Path, stat: &libc::stat, options: &Options) -> b
6978
(false, _, _) if options.interactive == InteractiveMode::PromptProtected => true,
7079
(_, true, _) => true,
7180
(_, false, true) => prompt_yes!(
72-
"remove write-protected regular empty file {}?",
73-
path.quote()
81+
"{}",
82+
translate!(
83+
"rm-prompt-remove-write-protected-regular-empty-file",
84+
"file" => path.quote()
85+
)
86+
),
87+
_ => prompt_yes!(
88+
"{}",
89+
translate!(
90+
"rm-prompt-remove-write-protected-regular-file",
91+
"file" => path.quote()
92+
)
7493
),
75-
_ => prompt_yes!("remove write-protected regular file {}?", path.quote()),
7694
}
7795
}
7896

@@ -90,17 +108,32 @@ fn prompt_dir_with_mode(path: &Path, mode: libc::mode_t, options: &Options) -> b
90108
(false, _, _, InteractiveMode::PromptProtected) => true,
91109
(false, false, false, InteractiveMode::Never) => true,
92110
(_, false, false, _) => prompt_yes!(
93-
"attempt removal of inaccessible directory {}?",
94-
path.quote()
111+
"{}",
112+
translate!(
113+
"rm-prompt-attempt-remove-inaccessible-directory",
114+
"path" => path.quote()
115+
)
95116
),
96117
(_, false, true, InteractiveMode::Always) => {
97118
prompt_yes!(
98-
"attempt removal of inaccessible directory {}?",
99-
path.quote()
119+
"{}",
120+
translate!(
121+
"rm-prompt-attempt-remove-inaccessible-directory",
122+
"path" => path.quote()
123+
)
100124
)
101125
}
102-
(_, true, false, _) => prompt_yes!("remove write-protected directory {}?", path.quote()),
103-
(_, _, _, InteractiveMode::Always) => prompt_yes!("remove directory {}?", path.quote()),
126+
(_, true, false, _) => prompt_yes!(
127+
"{}",
128+
translate!(
129+
"rm-prompt-remove-write-protected-directory",
130+
"path" => path.quote()
131+
)
132+
),
133+
(_, _, _, InteractiveMode::Always) => prompt_yes!(
134+
"{}",
135+
translate!("rm-prompt-remove-directory", "path" => path.quote())
136+
),
104137
(_, _, _, _) => true,
105138
}
106139
}

src/uu/rm/src/rm.rs

Lines changed: 73 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -267,21 +267,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
267267
}
268268

269269
if options.interactive == InteractiveMode::Once && (options.recursive || files.len() > 3) {
270-
let msg: String = format!(
271-
"remove {} {}{}",
272-
files.len(),
273-
if files.len() > 1 {
274-
"arguments"
275-
} else {
276-
"argument"
277-
},
278-
if options.recursive {
279-
" recursively?"
280-
} else {
281-
"?"
282-
}
283-
);
284-
if !prompt_yes!("{msg}") {
270+
let prompt_key = if options.recursive {
271+
"rm-prompt-remove-arguments-recursive"
272+
} else {
273+
"rm-prompt-remove-arguments"
274+
};
275+
let msg = translate!(prompt_key, "count" => files.len());
276+
if !prompt_yes!("{}", msg) {
285277
return Ok(());
286278
}
287279
}
@@ -842,21 +834,29 @@ fn prompt_file(path: &Path, options: &Options) -> bool {
842834
if options.interactive == InteractiveMode::Never {
843835
return true;
844836
}
845-
846837
let Ok(metadata) = fs::symlink_metadata(path) else {
847838
return true;
848839
};
849840

850841
if metadata.is_symlink() {
851842
return options.interactive != InteractiveMode::Always
852-
|| prompt_yes!("remove symbolic link {}?", path.quote());
843+
|| prompt_yes!(
844+
"{}",
845+
translate!("rm-prompt-remove-symbolic-link", "file" => path.quote())
846+
);
853847
}
854848

855849
if options.interactive == InteractiveMode::Always && is_writable_metadata(&metadata) {
856850
return if metadata.len() == 0 {
857-
prompt_yes!("remove regular empty file {}?", path.quote())
851+
prompt_yes!(
852+
"{}",
853+
translate!("rm-prompt-remove-regular-empty-file", "file" => path.quote())
854+
)
858855
} else {
859-
prompt_yes!("remove file {}?", path.quote())
856+
prompt_yes!(
857+
"{}",
858+
translate!("rm-prompt-remove-file", "file" => path.quote())
859+
)
860860
};
861861
}
862862

@@ -869,10 +869,19 @@ fn prompt_file_permission_readonly(path: &Path, options: &Options, metadata: &Me
869869
(false, InteractiveMode::PromptProtected) => true,
870870
_ if is_writable_metadata(metadata) => true,
871871
_ if metadata.len() == 0 => prompt_yes!(
872-
"remove write-protected regular empty file {}?",
873-
path.quote()
872+
"{}",
873+
translate!(
874+
"rm-prompt-remove-write-protected-regular-empty-file",
875+
"file" => path.quote()
876+
)
877+
),
878+
_ => prompt_yes!(
879+
"{}",
880+
translate!(
881+
"rm-prompt-remove-write-protected-regular-file",
882+
"file" => path.quote()
883+
)
874884
),
875-
_ => prompt_yes!("remove write-protected regular file {}?", path.quote()),
876885
}
877886
}
878887

@@ -907,15 +916,30 @@ fn handle_writable_directory(path: &Path, options: &Options, metadata: &Metadata
907916
(false, _, _, InteractiveMode::PromptProtected) => true,
908917
(false, false, false, InteractiveMode::Never) => true, // Don't prompt when interactive is never
909918
(_, false, false, _) => prompt_yes!(
910-
"attempt removal of inaccessible directory {}?",
911-
path.quote()
919+
"{}",
920+
translate!(
921+
"rm-prompt-attempt-remove-inaccessible-directory",
922+
"path" => path.quote()
923+
)
912924
),
913925
(_, false, true, InteractiveMode::Always) => prompt_yes!(
914-
"attempt removal of inaccessible directory {}?",
915-
path.quote()
926+
"{}",
927+
translate!(
928+
"rm-prompt-attempt-remove-inaccessible-directory",
929+
"path" => path.quote()
930+
)
931+
),
932+
(_, true, false, _) => prompt_yes!(
933+
"{}",
934+
translate!(
935+
"rm-prompt-remove-write-protected-directory",
936+
"path" => path.quote()
937+
)
938+
),
939+
(_, _, _, InteractiveMode::Always) => prompt_yes!(
940+
"{}",
941+
translate!("rm-prompt-remove-directory", "path" => path.quote())
916942
),
917-
(_, true, false, _) => prompt_yes!("remove write-protected directory {}?", path.quote()),
918-
(_, _, _, InteractiveMode::Always) => prompt_yes!("remove directory {}?", path.quote()),
919943
(_, _, _, _) => true,
920944
}
921945
}
@@ -929,8 +953,19 @@ fn handle_writable_directory(path: &Path, options: &Options, metadata: &Metadata
929953
let stdin_ok = options.__presume_input_tty.unwrap_or(false) || stdin().is_terminal();
930954
match (stdin_ok, not_user_writable, options.interactive) {
931955
(false, _, InteractiveMode::PromptProtected) => true,
932-
(_, true, _) => prompt_yes!("remove write-protected directory {}?", path.quote()),
933-
(_, _, InteractiveMode::Always) => prompt_yes!("remove directory {}?", path.quote()),
956+
(_, true, _) => prompt_yes!(
957+
"{}",
958+
translate!(
959+
"rm-prompt-remove-write-protected-directory",
960+
"path" => path.quote()
961+
)
962+
),
963+
(_, _, InteractiveMode::Always) => {
964+
prompt_yes!(
965+
"{}",
966+
translate!("rm-prompt-remove-directory", "path" => path.quote())
967+
)
968+
}
934969
(_, _, _) => true,
935970
}
936971
}
@@ -940,7 +975,10 @@ fn handle_writable_directory(path: &Path, options: &Options, metadata: &Metadata
940975
#[cfg(not(unix))]
941976
fn handle_writable_directory(path: &Path, options: &Options, _metadata: &Metadata) -> bool {
942977
if options.interactive == InteractiveMode::Always {
943-
prompt_yes!("remove directory {}?", path.quote())
978+
prompt_yes!(
979+
"{}",
980+
translate!("rm-prompt-remove-directory", "path" => path.quote())
981+
)
944982
} else {
945983
true
946984
}
@@ -981,7 +1019,10 @@ fn clean_trailing_slashes(path: &Path) -> &Path {
9811019
}
9821020

9831021
fn prompt_descend(path: &Path) -> bool {
984-
prompt_yes!("descend into directory {}?", path.quote())
1022+
prompt_yes!(
1023+
"{}",
1024+
translate!("rm-prompt-descend-into-directory", "path" => path.quote())
1025+
)
9851026
}
9861027

9871028
#[cfg(not(windows))]

0 commit comments

Comments
 (0)