1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

l10n: port chgrp for translation + add french

This commit is contained in:
Sylvestre Ledru 2025-06-13 22:41:49 +02:00
parent c9f76d41a7
commit d9a0804aa3
3 changed files with 70 additions and 18 deletions

View file

@ -1,3 +1,20 @@
chgrp-about = Change the group of each FILE to GROUP.
chgrp-usage = chgrp [OPTION]... GROUP FILE...
chgrp [OPTION]... --reference=RFILE FILE...
# Help messages
chgrp-help-print-help = Print help information.
chgrp-help-changes = like verbose but report only when a change is made
chgrp-help-quiet = suppress most error messages
chgrp-help-verbose = output a diagnostic for every file processed
chgrp-help-preserve-root = fail to operate recursively on '/'
chgrp-help-no-preserve-root = do not treat '/' specially (the default)
chgrp-help-reference = use RFILE's group rather than specifying GROUP values
chgrp-help-from = change the group only if its current group matches GROUP
chgrp-help-recursive = operate on files and directories recursively
# Error messages
chgrp-error-invalid-group-id = invalid group id: '{ $gid_str }'
chgrp-error-invalid-group = invalid group: '{ $group }'
chgrp-error-failed-to-get-attributes = failed to get attributes of { $file }
chgrp-error-invalid-user = invalid user: '{ $from_group }'

View file

@ -0,0 +1,20 @@
chgrp-about = Changer le groupe de chaque FICHIER vers GROUPE.
chgrp-usage = chgrp [OPTION]... GROUPE FICHIER...
chgrp [OPTION]... --reference=RFICHIER FICHIER...
# Messages d'aide
chgrp-help-print-help = Afficher les informations d'aide.
chgrp-help-changes = comme verbeux mais rapporter seulement lors d'un changement
chgrp-help-quiet = supprimer la plupart des messages d'erreur
chgrp-help-verbose = afficher un diagnostic pour chaque fichier traité
chgrp-help-preserve-root = échouer à opérer récursivement sur '/'
chgrp-help-no-preserve-root = ne pas traiter '/' spécialement (par défaut)
chgrp-help-reference = utiliser le groupe de RFICHIER plutôt que spécifier les valeurs de GROUPE
chgrp-help-from = changer le groupe seulement si son groupe actuel correspond à GROUPE
chgrp-help-recursive = opérer sur les fichiers et répertoires récursivement
# Messages d'erreur
chgrp-error-invalid-group-id = identifiant de groupe invalide : '{ $gid_str }'
chgrp-error-invalid-group = groupe invalide : '{ $group }'
chgrp-error-failed-to-get-attributes = échec de l'obtention des attributs de { $file }
chgrp-error-invalid-user = utilisateur invalide : '{ $from_group }'

View file

@ -12,26 +12,33 @@ use uucore::format_usage;
use uucore::perms::{GidUidOwnerFilter, IfFrom, chown_base, options};
use clap::{Arg, ArgAction, ArgMatches, Command};
use std::collections::HashMap;
use std::fs;
use std::os::unix::fs::MetadataExt;
use uucore::locale::get_message;
use uucore::locale::{get_message, get_message_with_args};
fn parse_gid_from_str(group: &str) -> Result<u32, String> {
if let Some(gid_str) = group.strip_prefix(':') {
// Handle :gid format
gid_str
.parse::<u32>()
.map_err(|_| format!("invalid group id: '{gid_str}'"))
gid_str.parse::<u32>().map_err(|_| {
get_message_with_args(
"chgrp-error-invalid-group-id",
HashMap::from([("gid_str".to_string(), gid_str.to_string())]),
)
})
} else {
// Try as group name first
match entries::grp2gid(group) {
Ok(g) => Ok(g),
// If group name lookup fails, try parsing as raw number
Err(_) => group
.parse::<u32>()
.map_err(|_| format!("invalid group: '{group}'")),
Err(_) => group.parse::<u32>().map_err(|_| {
get_message_with_args(
"chgrp-error-invalid-group",
HashMap::from([("group".to_string(), group.to_string())]),
)
}),
}
}
}
@ -45,7 +52,12 @@ fn get_dest_gid(matches: &ArgMatches) -> UResult<(Option<u32>, String)> {
raw_group = entries::gid2grp(gid).unwrap_or_else(|_| gid.to_string());
Some(gid)
})
.map_err_context(|| format!("failed to get attributes of {}", file.quote()))?
.map_err_context(|| {
get_message_with_args(
"chgrp-error-failed-to-get-attributes",
HashMap::from([("file".to_string(), file.quote().to_string())]),
)
})?
} else {
let group = matches
.get_one::<String>(options::ARG_GROUP)
@ -74,7 +86,10 @@ fn parse_gid_and_uid(matches: &ArgMatches) -> UResult<GidUidOwnerFilter> {
Err(_) => {
return Err(USimpleError::new(
1,
format!("invalid user: '{from_group}'"),
get_message_with_args(
"chgrp-error-invalid-user",
HashMap::from([("from_group".to_string(), from_group.to_string())]),
),
));
}
}
@ -105,14 +120,14 @@ pub fn uu_app() -> Command {
.arg(
Arg::new(options::HELP)
.long(options::HELP)
.help("Print help information.")
.help(get_message("chgrp-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("chgrp-help-changes"))
.action(ArgAction::SetTrue),
)
.arg(
@ -124,26 +139,26 @@ pub fn uu_app() -> Command {
.arg(
Arg::new(options::verbosity::QUIET)
.long(options::verbosity::QUIET)
.help("suppress most error messages")
.help(get_message("chgrp-help-quiet"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::verbosity::VERBOSE)
.short('v')
.long(options::verbosity::VERBOSE)
.help("output a diagnostic for every file processed")
.help(get_message("chgrp-help-verbose"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::preserve_root::PRESERVE)
.long(options::preserve_root::PRESERVE)
.help("fail to operate recursively on '/'")
.help(get_message("chgrp-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("chgrp-help-no-preserve-root"))
.action(ArgAction::SetTrue),
)
.arg(
@ -151,19 +166,19 @@ pub fn uu_app() -> Command {
.long(options::REFERENCE)
.value_name("RFILE")
.value_hint(clap::ValueHint::FilePath)
.help("use RFILE's group rather than specifying GROUP values"),
.help(get_message("chgrp-help-reference")),
)
.arg(
Arg::new(options::FROM)
.long(options::FROM)
.value_name("GROUP")
.help("change the group only if its current group matches GROUP"),
.help(get_message("chgrp-help-from")),
)
.arg(
Arg::new(options::RECURSIVE)
.short('R')
.long(options::RECURSIVE)
.help("operate on files and directories recursively")
.help(get_message("chgrp-help-recursive"))
.action(ArgAction::SetTrue),
)
// Add common arguments with chgrp, chown & chmod