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

Merge pull request #8184 from sylvestre/l10n-mktemp

l10n: port mktemp for translation + add french
This commit is contained in:
Daniel Hofstetter 2025-06-15 15:34:46 +02:00 committed by GitHub
commit a5a84a9524
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 75 additions and 38 deletions

View file

@ -1,2 +1,26 @@
mktemp-about = Create a temporary file or directory.
mktemp-usage = mktemp [OPTION]... [TEMPLATE]
# Help messages
mktemp-help-directory = Make a directory instead of a file
mktemp-help-dry-run = do not create anything; merely print a name (unsafe)
mktemp-help-quiet = Fail silently if an error occurs.
mktemp-help-suffix = append SUFFIX to TEMPLATE; SUFFIX must not contain a path separator. This option is implied if TEMPLATE does not end with X.
mktemp-help-p = short form of --tmpdir
mktemp-help-tmpdir = interpret TEMPLATE relative to DIR; if DIR is not specified, use $TMPDIR ($TMP on windows) if set, else /tmp. With this option, TEMPLATE must not be an absolute name; unlike with -t, TEMPLATE may contain slashes, but mktemp creates only the final component
mktemp-help-t = Generate a template (using the supplied prefix and TMPDIR (TMP on windows) if set) to create a filename template [deprecated]
# Error messages
mktemp-error-persist-file = could not persist file { $path }
mktemp-error-must-end-in-x = with --suffix, template { $template } must end in X
mktemp-error-too-few-xs = too few X's in template { $template }
mktemp-error-prefix-contains-separator = invalid template, { $template }, contains directory separator
mktemp-error-suffix-contains-separator = invalid suffix { $suffix }, contains directory separator
mktemp-error-invalid-template = invalid template, { $template }; with --tmpdir, it may not be absolute
mktemp-error-too-many-templates = too many templates
mktemp-error-not-found = failed to create { $template_type } via template { $template }: No such file or directory
mktemp-error-failed-print = failed to print directory name
# Template types
mktemp-template-type-directory = directory
mktemp-template-type-file = file

View file

@ -0,0 +1,26 @@
mktemp-about = Créer un fichier ou répertoire temporaire.
mktemp-usage = mktemp [OPTION]... [MODÈLE]
# Messages d'aide
mktemp-help-directory = Créer un répertoire au lieu d'un fichier
mktemp-help-dry-run = ne rien créer ; afficher seulement un nom (dangereux)
mktemp-help-quiet = Échouer silencieusement si une erreur se produit.
mktemp-help-suffix = ajouter SUFFIXE au MODÈLE ; SUFFIXE ne doit pas contenir un séparateur de chemin. Cette option est implicite si MODÈLE ne se termine pas par X.
mktemp-help-p = forme courte de --tmpdir
mktemp-help-tmpdir = interpréter MODÈLE relativement à RÉP ; si RÉP n'est pas spécifié, utiliser $TMPDIR ($TMP sur windows) si défini, sinon /tmp. Avec cette option, MODÈLE ne doit pas être un nom absolu ; contrairement à -t, MODÈLE peut contenir des barres obliques, mais mktemp ne crée que le composant final
mktemp-help-t = Générer un modèle (en utilisant le préfixe fourni et TMPDIR (TMP sur windows) si défini) pour créer un modèle de nom de fichier [obsolète]
# Messages d'erreur
mktemp-error-persist-file = impossible de conserver le fichier { $path }
mktemp-error-must-end-in-x = avec --suffix, le modèle { $template } doit se terminer par X
mktemp-error-too-few-xs = trop peu de X dans le modèle { $template }
mktemp-error-prefix-contains-separator = modèle invalide, { $template }, contient un séparateur de répertoire
mktemp-error-suffix-contains-separator = suffixe invalide { $suffix }, contient un séparateur de répertoire
mktemp-error-invalid-template = modèle invalide, { $template } ; avec --tmpdir, il ne peut pas être absolu
mktemp-error-too-many-templates = trop de modèles
mktemp-error-not-found = échec de la création de { $template_type } via le modèle { $template } : Aucun fichier ou répertoire de ce type
mktemp-error-failed-print = échec de l'affichage du nom de répertoire
# Types de modèle
mktemp-template-type-directory = répertoire
mktemp-template-type-file = fichier

View file

@ -9,7 +9,9 @@ use clap::{Arg, ArgAction, ArgMatches, Command, builder::ValueParser};
use uucore::display::{Quotable, println_verbatim};
use uucore::error::{FromIo, UError, UResult, UUsageError};
use uucore::format_usage;
use uucore::locale::{get_message, get_message_with_args};
use std::collections::HashMap;
use std::env;
use std::ffi::OsStr;
use std::io::ErrorKind;
@ -25,8 +27,6 @@ use rand::Rng;
use tempfile::Builder;
use thiserror::Error;
use uucore::locale::get_message;
static DEFAULT_TEMPLATE: &str = "tmp.XXXXXXXXXX";
static OPT_DIRECTORY: &str = "directory";
@ -44,35 +44,30 @@ const TMPDIR_ENV_VAR: &str = "TMPDIR";
#[cfg(windows)]
const TMPDIR_ENV_VAR: &str = "TMP";
#[derive(Debug, Error)]
#[derive(Error, Debug)]
enum MkTempError {
#[error("could not persist file {path}", path = .0.quote())]
#[error("{}", get_message_with_args("mktemp-error-persist-file", HashMap::from([("path".to_string(), .0.quote().to_string())])))]
PersistError(PathBuf),
#[error("with --suffix, template {template} must end in X", template = .0.quote())]
#[error("{}", get_message_with_args("mktemp-error-must-end-in-x", HashMap::from([("template".to_string(), .0.quote().to_string())])))]
MustEndInX(String),
#[error("too few X's in template {template}", template = .0.quote())]
#[error("{}", get_message_with_args("mktemp-error-too-few-xs", HashMap::from([("template".to_string(), .0.quote().to_string())])))]
TooFewXs(String),
/// The template prefix contains a path separator (e.g. `"a/bXXX"`).
#[error("invalid template, {template}, contains directory separator", template = .0.quote())]
#[error("{}", get_message_with_args("mktemp-error-prefix-contains-separator", HashMap::from([("template".to_string(), .0.quote().to_string())])))]
PrefixContainsDirSeparator(String),
/// The template suffix contains a path separator (e.g. `"XXXa/b"`).
#[error("invalid suffix {suffix}, contains directory separator", suffix = .0.quote())]
#[error("{}", get_message_with_args("mktemp-error-suffix-contains-separator", HashMap::from([("suffix".to_string(), .0.quote().to_string())])))]
SuffixContainsDirSeparator(String),
#[error("invalid template, {template}; with --tmpdir, it may not be absolute", template = .0.quote())]
#[error("{}", get_message_with_args("mktemp-error-invalid-template", HashMap::from([("template".to_string(), .0.quote().to_string())])))]
InvalidTemplate(String),
#[error("too many templates")]
#[error("{}", get_message("mktemp-error-too-many-templates"))]
TooManyTemplates,
/// When a specified temporary directory could not be found.
#[error("failed to create {template_type} via template {template}: No such file or directory",
template_type = .0,
template = .1.quote())]
#[error("{}", get_message_with_args("mktemp-error-not-found", HashMap::from([("template_type".to_string(), .0.clone()), ("template".to_string(), .1.quote().to_string())])))]
NotFound(String, String),
}
@ -295,7 +290,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
&& val == &clap::error::ContextValue::String("[template]".into())
})
{
return Err(UUsageError::new(1, "too many templates"));
return Err(UUsageError::new(
1,
get_message("mktemp-error-too-many-templates"),
));
}
return Err(e.into());
}
@ -340,7 +338,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} else {
res
};
println_verbatim(res?).map_err_context(|| "failed to print directory name".to_owned())
println_verbatim(res?).map_err_context(|| get_message("mktemp-error-failed-print"))
}
pub fn uu_app() -> Command {
@ -353,36 +351,33 @@ pub fn uu_app() -> Command {
Arg::new(OPT_DIRECTORY)
.short('d')
.long(OPT_DIRECTORY)
.help("Make a directory instead of a file")
.help(get_message("mktemp-help-directory"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(OPT_DRY_RUN)
.short('u')
.long(OPT_DRY_RUN)
.help("do not create anything; merely print a name (unsafe)")
.help(get_message("mktemp-help-dry-run"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(OPT_QUIET)
.short('q')
.long("quiet")
.help("Fail silently if an error occurs.")
.help(get_message("mktemp-help-quiet"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(OPT_SUFFIX)
.long(OPT_SUFFIX)
.help(
"append SUFFIX to TEMPLATE; SUFFIX must not contain a path separator. \
This option is implied if TEMPLATE does not end with X.",
)
.help(get_message("mktemp-help-suffix"))
.value_name("SUFFIX"),
)
.arg(
Arg::new(OPT_P)
.short('p')
.help("short form of --tmpdir")
.help(get_message("mktemp-help-p"))
.value_name("DIR")
.num_args(1)
.value_parser(ValueParser::path_buf())
@ -391,12 +386,7 @@ pub fn uu_app() -> Command {
.arg(
Arg::new(OPT_TMPDIR)
.long(OPT_TMPDIR)
.help(
"interpret TEMPLATE relative to DIR; if DIR is not specified, use \
$TMPDIR ($TMP on windows) if set, else /tmp. With this option, \
TEMPLATE must not be an absolute name; unlike with -t, TEMPLATE \
may contain slashes, but mktemp creates only the final component",
)
.help(get_message("mktemp-help-tmpdir"))
.value_name("DIR")
// Allows use of default argument just by setting --tmpdir. Else,
// use provided input to generate tmpdir
@ -410,10 +400,7 @@ pub fn uu_app() -> Command {
.arg(
Arg::new(OPT_T)
.short('t')
.help(
"Generate a template (using the supplied prefix and TMPDIR \
(TMP on windows) if set) to create a filename template [deprecated]",
)
.help(get_message("mktemp-help-t"))
.action(ArgAction::SetTrue),
)
.arg(Arg::new(ARG_TEMPLATE).num_args(..=1))
@ -475,7 +462,7 @@ fn make_temp_dir(dir: &Path, prefix: &str, rand: usize, suffix: &str) -> UResult
let filename = format!("{prefix}{}{suffix}", "X".repeat(rand));
let path = Path::new(dir).join(filename);
let s = path.display().to_string();
Err(MkTempError::NotFound("directory".to_string(), s).into())
Err(MkTempError::NotFound(get_message("mktemp-template-type-directory"), s).into())
}
Err(e) => Err(e.into()),
}
@ -505,7 +492,7 @@ fn make_temp_file(dir: &Path, prefix: &str, rand: usize, suffix: &str) -> UResul
let filename = format!("{prefix}{}{suffix}", "X".repeat(rand));
let path = Path::new(dir).join(filename);
let s = path.display().to_string();
Err(MkTempError::NotFound("file".to_string(), s).into())
Err(MkTempError::NotFound(get_message("mktemp-template-type-file"), s).into())
}
Err(e) => Err(e.into()),
}