1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #8118 from sylvestre/l10n-expr

l10n: port expr for translation + add french
This commit is contained in:
Daniel Hofstetter 2025-06-09 09:24:51 +02:00 committed by GitHub
commit 65461537bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 104 additions and 18 deletions

View file

@ -43,3 +43,23 @@ expr-after-help = Print the value of EXPRESSION to standard output. A blank line
- EXPR_DEBUG_RPN=1: dump expression represented in reverse polish notation - EXPR_DEBUG_RPN=1: dump expression represented in reverse polish notation
- EXPR_DEBUG_SYA_STEP=1: dump each parser step - EXPR_DEBUG_SYA_STEP=1: dump each parser step
- EXPR_DEBUG_AST=1: dump expression represented abstract syntax tree - EXPR_DEBUG_AST=1: dump expression represented abstract syntax tree
# Help messages
expr-help-version = output version information and exit
expr-help-help = display this help and exit
# Error messages
expr-error-unexpected-argument = syntax error: unexpected argument { $arg }
expr-error-missing-argument = syntax error: missing argument after { $arg }
expr-error-non-integer-argument = non-integer argument
expr-error-missing-operand = missing operand
expr-error-division-by-zero = division by zero
expr-error-invalid-regex-expression = Invalid regex expression
expr-error-expected-closing-brace-after = syntax error: expecting ')' after { $arg }
expr-error-expected-closing-brace-instead-of = syntax error: expecting ')' instead of { $arg }
expr-error-unmatched-opening-parenthesis = Unmatched ( or \(
expr-error-unmatched-closing-parenthesis = Unmatched ) or \)
expr-error-unmatched-opening-brace = Unmatched {"\\{"}
expr-error-invalid-bracket-content = Invalid content of {"\\{\\}"}
expr-error-trailing-backslash = Trailing backslash
expr-error-too-big-range-quantifier-index = Regular expression too big

View file

@ -0,0 +1,65 @@
expr-about = Afficher la valeur de EXPRESSION sur la sortie standard
expr-usage = expr [EXPRESSION]
expr [OPTIONS]
expr-after-help = Afficher la valeur de EXPRESSION sur la sortie standard. Une ligne vide ci-dessous
sépare les groupes de précédence croissante.
EXPRESSION peut être :
- ARG1 | ARG2: ARG1 s'il n'est ni nul ni 0, sinon ARG2
- ARG1 & ARG2: ARG1 si aucun argument n'est nul ou 0, sinon 0
- ARG1 < ARG2: ARG1 est inférieur à ARG2
- ARG1 <= ARG2: ARG1 est inférieur ou égal à ARG2
- ARG1 = ARG2: ARG1 est égal à ARG2
- ARG1 != ARG2: ARG1 est différent de ARG2
- ARG1 >= ARG2: ARG1 est supérieur ou égal à ARG2
- ARG1 > ARG2: ARG1 est supérieur à ARG2
- ARG1 + ARG2: somme arithmétique de ARG1 et ARG2
- ARG1 - ARG2: différence arithmétique de ARG1 et ARG2
- ARG1 * ARG2: produit arithmétique de ARG1 et ARG2
- ARG1 / ARG2: quotient arithmétique de ARG1 divisé par ARG2
- ARG1 % ARG2: reste arithmétique de ARG1 divisé par ARG2
- STRING : REGEXP: correspondance de motif ancré de REGEXP dans STRING
- match STRING REGEXP: identique à STRING : REGEXP
- substr STRING POS LENGTH: sous-chaîne de STRING, POS compté à partir de 1
- index STRING CHARS: index dans STRING où l'un des CHARS est trouvé, ou 0
- length STRING: longueur de STRING
- + TOKEN: interpréter TOKEN comme une chaîne, même si c'est un mot-clé comme match
ou un opérateur comme /
- ( EXPRESSION ): valeur de EXPRESSION
Attention : de nombreux opérateurs doivent être échappés ou mis entre guillemets pour les shells.
Les comparaisons sont arithmétiques si les deux ARG sont des nombres, sinon lexicographiques.
Les correspondances de motifs retournent la chaîne correspondant entre \( et \) ou null ; si
\( et \) ne sont pas utilisés, elles retournent le nombre de caractères correspondants ou 0.
Le statut de sortie est 0 si EXPRESSION n'est ni nulle ni 0, 1 si EXPRESSION
est nulle ou 0, 2 si EXPRESSION est syntaxiquement invalide, et 3 si une
erreur s'est produite.
Variables d'environnement :
- EXPR_DEBUG_TOKENS=1: afficher les jetons de l'expression
- EXPR_DEBUG_RPN=1: afficher l'expression représentée en notation polonaise inverse
- EXPR_DEBUG_SYA_STEP=1: afficher chaque étape de l'analyseur
- EXPR_DEBUG_AST=1: afficher l'arbre de syntaxe abstraite représentant l'expression
# Messages d'aide
expr-help-version = afficher les informations de version et quitter
expr-help-help = afficher cette aide et quitter
# Messages d'erreur
expr-error-unexpected-argument = erreur de syntaxe : argument inattendu { $arg }
expr-error-missing-argument = erreur de syntaxe : argument manquant après { $arg }
expr-error-non-integer-argument = argument non entier
expr-error-missing-operand = opérande manquant
expr-error-division-by-zero = division par zéro
expr-error-invalid-regex-expression = Expression regex invalide
expr-error-expected-closing-brace-after = erreur de syntaxe : ')' attendu après { $arg }
expr-error-expected-closing-brace-instead-of = erreur de syntaxe : ')' attendu au lieu de { $arg }
expr-error-unmatched-opening-parenthesis = Parenthèse ouvrante ( ou \( non appariée
expr-error-unmatched-closing-parenthesis = Parenthèse fermante ) ou \) non appariée
expr-error-unmatched-opening-brace = Accolade ouvrante {"\\{"} non appariée
expr-error-invalid-bracket-content = Contenu invalide de {"\\{\\}"}
expr-error-trailing-backslash = Barre oblique inverse en fin
expr-error-too-big-range-quantifier-index = Expression régulière trop grande

View file

@ -4,9 +4,10 @@
// file that was distributed with this source code. // file that was distributed with this source code.
use clap::{Arg, ArgAction, Command}; use clap::{Arg, ArgAction, Command};
use std::collections::HashMap;
use syntax_tree::{AstNode, is_truthy}; use syntax_tree::{AstNode, is_truthy};
use thiserror::Error; use thiserror::Error;
use uucore::locale::get_message; use uucore::locale::{get_message, get_message_with_args};
use uucore::{ use uucore::{
display::Quotable, display::Quotable,
error::{UError, UResult}, error::{UError, UResult},
@ -25,33 +26,33 @@ pub type ExprResult<T> = Result<T, ExprError>;
#[derive(Error, Clone, Debug, PartialEq, Eq)] #[derive(Error, Clone, Debug, PartialEq, Eq)]
pub enum ExprError { pub enum ExprError {
#[error("syntax error: unexpected argument {}", .0.quote())] #[error("{}", get_message_with_args("expr-error-unexpected-argument", HashMap::from([("arg".to_string(), _0.quote().to_string())])))]
UnexpectedArgument(String), UnexpectedArgument(String),
#[error("syntax error: missing argument after {}", .0.quote())] #[error("{}", get_message_with_args("expr-error-missing-argument", HashMap::from([("arg".to_string(), _0.quote().to_string())])))]
MissingArgument(String), MissingArgument(String),
#[error("non-integer argument")] #[error("{}", get_message("expr-error-non-integer-argument"))]
NonIntegerArgument, NonIntegerArgument,
#[error("missing operand")] #[error("{}", get_message("expr-error-missing-operand"))]
MissingOperand, MissingOperand,
#[error("division by zero")] #[error("{}", get_message("expr-error-division-by-zero"))]
DivisionByZero, DivisionByZero,
#[error("Invalid regex expression")] #[error("{}", get_message("expr-error-invalid-regex-expression"))]
InvalidRegexExpression, InvalidRegexExpression,
#[error("syntax error: expecting ')' after {}", .0.quote())] #[error("{}", get_message_with_args("expr-error-expected-closing-brace-after", HashMap::from([("arg".to_string(), _0.quote().to_string())])))]
ExpectedClosingBraceAfter(String), ExpectedClosingBraceAfter(String),
#[error("syntax error: expecting ')' instead of {}", .0.quote())] #[error("{}", get_message_with_args("expr-error-expected-closing-brace-instead-of", HashMap::from([("arg".to_string(), _0.quote().to_string())])))]
ExpectedClosingBraceInsteadOf(String), ExpectedClosingBraceInsteadOf(String),
#[error("Unmatched ( or \\(")] #[error("{}", get_message("expr-error-unmatched-opening-parenthesis"))]
UnmatchedOpeningParenthesis, UnmatchedOpeningParenthesis,
#[error("Unmatched ) or \\)")] #[error("{}", get_message("expr-error-unmatched-closing-parenthesis"))]
UnmatchedClosingParenthesis, UnmatchedClosingParenthesis,
#[error("Unmatched \\{{")] #[error("{}", get_message("expr-error-unmatched-opening-brace"))]
UnmatchedOpeningBrace, UnmatchedOpeningBrace,
#[error("Invalid content of \\{{\\}}")] #[error("{}", get_message("expr-error-invalid-bracket-content"))]
InvalidBracketContent, InvalidBracketContent,
#[error("Trailing backslash")] #[error("{}", get_message("expr-error-trailing-backslash"))]
TrailingBackslash, TrailingBackslash,
#[error("Regular expression too big")] #[error("{}", get_message("expr-error-too-big-range-quantifier-index"))]
TooBigRangeQuantifierIndex, TooBigRangeQuantifierIndex,
} }
@ -77,13 +78,13 @@ pub fn uu_app() -> Command {
.arg( .arg(
Arg::new(options::VERSION) Arg::new(options::VERSION)
.long(options::VERSION) .long(options::VERSION)
.help("output version information and exit") .help(get_message("expr-help-version"))
.action(ArgAction::Version), .action(ArgAction::Version),
) )
.arg( .arg(
Arg::new(options::HELP) Arg::new(options::HELP)
.long(options::HELP) .long(options::HELP)
.help("display this help and exit") .help(get_message("expr-help-help"))
.action(ArgAction::Help), .action(ArgAction::Help),
) )
.arg( .arg(
@ -96,7 +97,7 @@ pub fn uu_app() -> Command {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// For expr utility we do not want getopts. // For expr utility we do not want getopts.
// The following usage should work without escaping hyphens: `expr -15 = 1 + 2 \* \( 3 - -4 \)` // The following usage should work without escaping hyphens: `expr -15 = 1 + 2 \* \( 3 - -4 \)`
let args: Vec<String> = args let args: Vec<String> = args
.skip(1) // Skip binary name .skip(1) // Skip binary name
.map(|a| a.to_string_lossy().to_string()) .map(|a| a.to_string_lossy().to_string())