Skip to content

Commit 822c721

Browse files
committed
l10n: port chown for translation + add french
1 parent c83c6d8 commit 822c721

File tree

3 files changed

+78
-20
lines changed

3 files changed

+78
-20
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
11
chown-about = Change file owner and group
22
chown-usage = chown [OPTION]... [OWNER][:[GROUP]] FILE...
33
chown [OPTION]... --reference=RFILE FILE...
4+
5+
# Help messages
6+
chown-help-print-help = Print help information.
7+
chown-help-changes = like verbose but report only when a change is made
8+
chown-help-from = change the owner and/or group of each file only if its
9+
current owner and/or group match those specified here.
10+
Either may be omitted, in which case a match is not required
11+
for the omitted attribute
12+
chown-help-preserve-root = fail to operate recursively on '/'
13+
chown-help-no-preserve-root = do not treat '/' specially (the default)
14+
chown-help-quiet = suppress most error messages
15+
chown-help-recursive = operate on files and directories recursively
16+
chown-help-reference = use RFILE's owner and group rather than specifying OWNER:GROUP values
17+
chown-help-verbose = output a diagnostic for every file processed
18+
19+
# Error messages
20+
chown-error-failed-to-get-attributes = failed to get attributes of { $file }
21+
chown-error-invalid-user = invalid user: { $user }
22+
chown-error-invalid-group = invalid group: { $group }
23+
chown-error-invalid-spec = invalid spec: { $spec }

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
chown-about = Changer le propriétaire et le groupe des fichiers
2+
chown-usage = chown [OPTION]... [PROPRIÉTAIRE][:[GROUPE]] FICHIER...
3+
chown [OPTION]... --reference=RFICHIER FICHIER...
4+
5+
# Messages d'aide
6+
chown-help-print-help = Afficher les informations d'aide.
7+
chown-help-changes = comme verbeux mais rapporter seulement lors d'un changement
8+
chown-help-from = changer le propriétaire et/ou le groupe de chaque fichier seulement si son
9+
propriétaire et/ou groupe actuel correspondent à ceux spécifiés ici.
10+
L'un ou l'autre peut être omis, auquel cas une correspondance n'est pas requise
11+
pour l'attribut omis
12+
chown-help-preserve-root = échouer à opérer récursivement sur '/'
13+
chown-help-no-preserve-root = ne pas traiter '/' spécialement (par défaut)
14+
chown-help-quiet = supprimer la plupart des messages d'erreur
15+
chown-help-recursive = opérer sur les fichiers et répertoires récursivement
16+
chown-help-reference = utiliser le propriétaire et groupe de RFICHIER plutôt que spécifier les valeurs PROPRIÉTAIRE:GROUPE
17+
chown-help-verbose = afficher un diagnostic pour chaque fichier traité
18+
19+
# Messages d'erreur
20+
chown-error-failed-to-get-attributes = échec de l'obtention des attributs de { $file }
21+
chown-error-invalid-user = utilisateur invalide : { $user }
22+
chown-error-invalid-group = groupe invalide : { $group }
23+
chown-error-invalid-spec = spécification invalide : { $spec }

src/uu/chown/src/chown.rs

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ use clap::{Arg, ArgAction, ArgMatches, Command};
1717
use std::fs;
1818
use std::os::unix::fs::MetadataExt;
1919

20-
use uucore::locale::get_message;
20+
use std::collections::HashMap;
21+
use uucore::locale::{get_message, get_message_with_args};
2122

2223
fn parse_gid_uid_and_filter(matches: &ArgMatches) -> UResult<GidUidOwnerFilter> {
2324
let filter = if let Some(spec) = matches.get_one::<String>(options::FROM) {
@@ -35,8 +36,12 @@ fn parse_gid_uid_and_filter(matches: &ArgMatches) -> UResult<GidUidOwnerFilter>
3536
let dest_gid: Option<u32>;
3637
let raw_owner: String;
3738
if let Some(file) = matches.get_one::<String>(options::REFERENCE) {
38-
let meta = fs::metadata(file)
39-
.map_err_context(|| format!("failed to get attributes of {}", file.quote()))?;
39+
let meta = fs::metadata(file).map_err_context(|| {
40+
get_message_with_args(
41+
"chown-error-failed-to-get-attributes",
42+
HashMap::from([("file".to_string(), file.quote().to_string())]),
43+
)
44+
})?;
4045
let gid = meta.gid();
4146
let uid = meta.uid();
4247
dest_gid = Some(gid);
@@ -84,56 +89,51 @@ pub fn uu_app() -> Command {
8489
.arg(
8590
Arg::new(options::HELP)
8691
.long(options::HELP)
87-
.help("Print help information.")
92+
.help(get_message("chown-help-print-help"))
8893
.action(ArgAction::Help),
8994
)
9095
.arg(
9196
Arg::new(options::verbosity::CHANGES)
9297
.short('c')
9398
.long(options::verbosity::CHANGES)
94-
.help("like verbose but report only when a change is made")
99+
.help(get_message("chown-help-changes"))
95100
.action(ArgAction::SetTrue),
96101
)
97102
.arg(
98103
Arg::new(options::FROM)
99104
.long(options::FROM)
100-
.help(
101-
"change the owner and/or group of each file only if its \
102-
current owner and/or group match those specified here. \
103-
Either may be omitted, in which case a match is not required \
104-
for the omitted attribute",
105-
)
105+
.help(get_message("chown-help-from"))
106106
.value_name("CURRENT_OWNER:CURRENT_GROUP"),
107107
)
108108
.arg(
109109
Arg::new(options::preserve_root::PRESERVE)
110110
.long(options::preserve_root::PRESERVE)
111-
.help("fail to operate recursively on '/'")
111+
.help(get_message("chown-help-preserve-root"))
112112
.action(ArgAction::SetTrue),
113113
)
114114
.arg(
115115
Arg::new(options::preserve_root::NO_PRESERVE)
116116
.long(options::preserve_root::NO_PRESERVE)
117-
.help("do not treat '/' specially (the default)")
117+
.help(get_message("chown-help-no-preserve-root"))
118118
.action(ArgAction::SetTrue),
119119
)
120120
.arg(
121121
Arg::new(options::verbosity::QUIET)
122122
.long(options::verbosity::QUIET)
123-
.help("suppress most error messages")
123+
.help(get_message("chown-help-quiet"))
124124
.action(ArgAction::SetTrue),
125125
)
126126
.arg(
127127
Arg::new(options::RECURSIVE)
128128
.short('R')
129129
.long(options::RECURSIVE)
130-
.help("operate on files and directories recursively")
130+
.help(get_message("chown-help-recursive"))
131131
.action(ArgAction::SetTrue),
132132
)
133133
.arg(
134134
Arg::new(options::REFERENCE)
135135
.long(options::REFERENCE)
136-
.help("use RFILE's owner and group rather than specifying OWNER:GROUP values")
136+
.help(get_message("chown-help-reference"))
137137
.value_name("RFILE")
138138
.value_hint(clap::ValueHint::FilePath)
139139
.num_args(1..),
@@ -148,7 +148,7 @@ pub fn uu_app() -> Command {
148148
Arg::new(options::verbosity::VERBOSE)
149149
.long(options::verbosity::VERBOSE)
150150
.short('v')
151-
.help("output a diagnostic for every file processed")
151+
.help(get_message("chown-help-verbose"))
152152
.action(ArgAction::SetTrue),
153153
)
154154
// Add common arguments with chgrp, chown & chmod
@@ -177,7 +177,10 @@ fn parse_uid(user: &str, spec: &str, sep: char) -> UResult<Option<u32>> {
177177
Ok(uid) => Ok(Some(uid)),
178178
Err(_) => Err(USimpleError::new(
179179
1,
180-
format!("invalid user: {}", spec.quote()),
180+
get_message_with_args(
181+
"chown-error-invalid-user",
182+
HashMap::from([("user".to_string(), spec.quote().to_string())]),
183+
),
181184
)),
182185
}
183186
}
@@ -196,7 +199,10 @@ fn parse_gid(group: &str, spec: &str) -> UResult<Option<u32>> {
196199
Ok(gid) => Ok(Some(gid)),
197200
Err(_) => Err(USimpleError::new(
198201
1,
199-
format!("invalid group: {}", spec.quote()),
202+
get_message_with_args(
203+
"chown-error-invalid-group",
204+
HashMap::from([("group".to_string(), spec.quote().to_string())]),
205+
),
200206
)),
201207
},
202208
}
@@ -231,7 +237,10 @@ fn parse_spec(spec: &str, sep: char) -> UResult<(Option<u32>, Option<u32>)> {
231237
// we should fail with an error
232238
return Err(USimpleError::new(
233239
1,
234-
format!("invalid spec: {}", spec.quote()),
240+
get_message_with_args(
241+
"chown-error-invalid-spec",
242+
HashMap::from([("spec".to_string(), spec.quote().to_string())]),
243+
),
235244
));
236245
}
237246

@@ -241,9 +250,15 @@ fn parse_spec(spec: &str, sep: char) -> UResult<(Option<u32>, Option<u32>)> {
241250
#[cfg(test)]
242251
mod test {
243252
use super::*;
253+
use std::env;
254+
use uucore::locale;
244255

245256
#[test]
246257
fn test_parse_spec() {
258+
unsafe {
259+
env::set_var("LANG", "C");
260+
}
261+
let _ = locale::setup_localization("chown");
247262
assert!(matches!(parse_spec(":", ':'), Ok((None, None))));
248263
assert!(matches!(parse_spec(".", ':'), Ok((None, None))));
249264
assert!(matches!(parse_spec(".", '.'), Ok((None, None))));

0 commit comments

Comments
 (0)