8000 l10n: port stty for translation + add french by sylvestre · Pull Request #8257 · uutils/coreutils · GitHub
[go: up one dir, main page]

Skip to content

l10n: port stty for translation + add french #8257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
l10n: port stty for translation + add french
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
  • Loading branch information
sylvestre and cakebaker committed Jun 24, 2025
commit 95e3d6e92c2480f78fe9560560d70789b38b28bc
29 changes: 25 additions & 4 deletions src/uu/stty/locales/en-US.ftl
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
stty-about = Print or change terminal characteristics.
stty-usage = stty [-F DEVICE | --file=DEVICE] [SETTING]...
stty [-F DEVICE | --file=DEVICE] [-a|--all]
stty [-F DEVICE | --file=DEVICE] [-g|--save]
stty-usage = "stty [-F DEVICE | --file=DEVICE] [SETTING]...
or: stty [-F DEVICE | --file=DEVICE] [-a|--all]
or: stty [-F DEVICE | --file=DEVICE] [-g|--save]"

stty-about = "Print or change terminal characteristics."

stty-option-all = "print all current settings in human-readable form"
stty-option-save = "print all current settings in a stty-readable form"
stty-option-file = "open and use the specified DEVICE instead of stdin"
stty-option-settings = "settings to change"

stty-error-options-mutually-exclusive = "the options for verbose and stty-readable output styles are mutually exclusive"
stty-error-output-style-no-modes = "when specifying an output style, modes may not be set"
stty-error-missing-argument = "missing argument to '{$arg}'"
stty-error-invalid-speed = "invalid {$arg} '{$speed}'"
stty-error-invalid-argument = "invalid argument '{$arg}'"
stty-error-invalid-integer-argument = "invalid integer argument: {$value}"
stty-error-invalid-integer-argument-value-too-large = "invalid integer argument: {$value}: Value too large for defined data type"

# Output format strings
stty-output-speed = speed {$speed} baud;
stty-output-rows-columns = rows {$rows}; columns {$columns};
stty-output-line = line = {$line};
stty-output-undef = <undef>
stty-output-min-time = min = {$min}; time = {$time};
25 changes: 25 additions & 0 deletions src/uu/stty/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
stty-usage = "stty [-F PÉRIPHÉRIQUE | --file=PÉRIPHÉRIQUE] [PARAMÈTRE]...
ou: stty [-F PÉRIPHÉRIQUE | --file=PÉRIPHÉRIQUE] [-a|--all]
ou: stty [-F PÉRIPHÉRIQUE | --file=PÉRIPHÉRIQUE] [-g|--save]"

stty-about = "Afficher ou modifier les caractéristiques du terminal."

stty-option-all = "afficher tous les paramètres actuels sous forme lisible"
stty-option-save = "afficher tous les paramètres actuels sous forme lisible par stty"
stty-option-file = "ouvrir et utiliser le PÉRIPHÉRIQUE spécifié au lieu de stdin"
stty-option-settings = "paramètres à modifier"

stty-error-options-mutually-exclusive = "les options pour les styles de sortie verbeux et lisible par stty s'excluent mutuellement"
stty-error-output-style-no-modes = "lors de la spécification d'un style de sortie, les modes ne peuvent pas être définis"
stty-error-missing-argument = "argument manquant pour '{$arg}'"
stty-error-invalid-speed = "{$arg} invalide '{$speed}'"
stty-error-invalid-argument = "argument invalide '{$arg}'"
stty-error-invalid-integer-argument = "argument entier invalide : {$value}"
stty-error-invalid-integer-argument-value-too-large = "argument entier invalide : {$value} : Valeur trop grande pour le type de données défini"

# Chaînes de format de sortie
stty-output-speed = vitesse {$speed} bauds ;
stty-output-rows-columns = lignes {$rows} ; colonnes {$columns} ;
stty-output-line = ligne = {$line} ;
stty-output-undef = <indéfini>
stty-output-min-time = min = {$min} ; temps = {$time} ;
164 changes: 130 additions & 34 deletions src/uu/stty/src/stty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
cfgetospeed, cfsetospeed, tcgetattr, tcsetattr,
};
use nix::{ioctl_read_bad, ioctl_write_ptr_bad};
use std::collections::HashMap;
use std::fs::File;
use std::io::{self, Stdout, stdout};
use std::os::fd::{AsFd, BorrowedFd};
use std::os::unix::fs::OpenOptionsExt;
use std::os::unix::io::{AsRawFd, RawFd};
use uucore::error::{UResult, USimpleError};
use uucore::format_usage;
use uucore::locale::get_message;
use uucore::locale::{get_message, get_message_with_args};

#[cfg(not(any(
target_os = "freebsd",
Expand Down Expand Up @@ -104,8 +105,8 @@
}

enum ControlCharMappingError {
IntOutOfRange,
MultipleChars,
IntOutOfRange(String),
MultipleChars(String),
}

enum SpecialSetting {
Expand Down Expand Up @@ -226,14 +227,14 @@
if opts.save && opts.all {
return Err(USimpleError::new(
1,
"the options for verbose and stty-readable output styles are mutually exclusive",
get_message("stty-error-options-mutually-exclusive"),
));
}

if opts.settings.is_some() && (opts.save || opts.all) {
return Err(USimpleError::new(
1,
"when specifying an output style, modes may not be set",
get_message("stty-error-output-style-no-modes"),
));
}

Expand All @@ -248,18 +249,26 @@
if let Some(mapping) = args_iter.next() {
let cc_mapping = string_to_control_char(mapping).map_err(|e| {
let message = match e {
ControlCharMappingError::IntOutOfRange => format!(
"invalid integer argument: '{mapping}': Value too large for defined data type"
ControlCharMappingError::IntOutOfRange(val) => get_message_with_args(
"stty-error-invalid-integer-argument-value-too-large",
HashMap::from([("value".to_string(), format!("'{}'", val))]),
),
ControlCharMappingError::MultipleChars(val) => get_message_with_args(
10000 "stty-error-invalid-integer-argument",
HashMap::from([("value".to_string(), format!("'{}'", val))]),
),
ControlCharMappingError::MultipleChars => {
format!("invalid integer argument: '{mapping}'")
}
};
USimpleError::new(1, message)
})?;
valid_args.push(ArgOptions::Mapping((char_index, cc_mapping)));
} else {
return Err(USimpleError::new(1, format!("missing argument to '{arg}'")));
return Err(USimpleError::new(
1,
get_message_with_args(
"stty-error-missing-argument",
HashMap::from([("arg".to_string(), arg.to_string())]),
),
));
}
// ispeed/ospeed baud rate setting
} else if *arg == "ispeed" || *arg == "ospeed" {
Expand All @@ -268,11 +277,26 @@
if let Some(baud_flag) = string_to_baud(speed) {
valid_args.push(ArgOptions::Flags(baud_flag));
} else {
return Err(USimpleError::new(1, format!("invalid {arg} '{speed}'")));
return Err(USimpleError::new(
1,
get_message_with_args(
"stty-error-invalid-speed",
HashMap::from([
("arg".to_string(), arg.to_string()),
("speed".to_string(), speed.to_string()),
]),
),
));
}
}
None => {
return Err(USimpleError::new(1, format!("missing argument to '{arg}'")));
return Err(USimpleError::new(
1,
get_message_with_args(
"stty-error-missing-argument",
HashMap::from([("arg".to_string(), arg.to_string())]),
),
));
}
}
// baud rate setting
Expand All @@ -288,7 +312,13 @@
AllFlags::OutputFlags((flag, remove)) => check_flag_group(flag, remove),
};
if remove_group {
return Err(USimpleError::new(1, format!("invalid argument '{arg}'")));
return Err(USimpleError::new(
1,
get_message_with_args(
"stty-error-invalid-argument",
HashMap::from([("arg".to_string(), arg.to_string())]),
),
));

Check warning on line 321 in src/uu/stty/src/stty.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/stty/src/stty.rs#L315-L321

Added lines #L315 - L321 were not covered by tests
}
valid_args.push(flag.into());
} else if *arg == "rows" {
Expand All @@ -298,11 +328,20 @@
} else {
return Err(USimpleError::new(
1,
format!("invalid integer argument: '{rows}'"),
get_message_with_args(
"stty-error-invalid-integer-argument",
HashMap::from([("value".to_string(), format!("'{}'", rows))]),
),
));
}
} else {
return Err(USimpleError::new(1, format!("missing argument to '{arg}'")));
return Err(USimpleError::new(
1,
get_message_with_args(
"stty-error-missing-argument",
HashMap::from([("arg".to_string(), arg.to_string())]),
),
));
}
} else if *arg == "columns" || *arg == "cols" {
if let Some(cols) = args_iter.next() {
Expand All @@ -311,17 +350,32 @@
} else {
return Err(USimpleError::new(
1,
format!("invalid integer argument: '{cols}'"),
get_message_with_args(
"stty-error-invalid-integer-argument",
HashMap::from([("value".to_string(), format!("'{}'", cols))]),
),
));
}
} else {
return Err(USimpleError::new(1, format!("missing argument to '{arg}'")));
return Err(USimpleError::new(
1,
get_message_with_args(
"stty-error-missing-argument",
HashMap::from([("arg".to_string(), arg.to_string())]),
),
));
}
} else if *arg == "size" {
valid_args.push(ArgOptions::Print(PrintSetting::Size));
// not a valid option
} else {
return Err(USimpleError::new(1, format!("invalid argument '{arg}'")));
return Err(USimpleError::new(
1,
get_message_with_args(
"stty-error-invalid-argument",
HashMap::from([("arg".to_string(), arg.to_string())]),
),
));
}
}

Expand Down Expand Up @@ -391,7 +445,13 @@
target_os = "netbsd",
target_os = "openbsd"
))]
print!("speed {speed} baud; ");
print!(
"{} ",
get_message_with_args(
"stty-output-speed",
HashMap::from([("speed".to_string(), speed.to_string())])
)
);

// Other platforms need to use the baud rate enum, so printing the right value
// becomes slightly more complicated.
Expand All @@ -405,15 +465,30 @@
)))]
for (text, baud_rate) in BAUD_RATES {
if *baud_rate == speed {
print!("speed {text} baud; ");
print!(
"{} ",
get_message_with_args(
"stty-output-speed",
HashMap::from([("speed".to_string(), text.to_string())])

Check warning on line 472 in src/uu/stty/src/stty.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/stty/src/stty.rs#L468-L472

Added lines #L468 - L472 were not covered by tests
)
);
break;
}
}

if opts.all {
let mut size = TermSize::default();
unsafe { tiocgwinsz(opts.file.as_raw_fd(), &raw mut size)? };
print!("rows {}; columns {}; ", size.rows, size.columns);
print!(
"{} ",
get_message_with_args(
"stty-output-rows-columns",
HashMap::from([
("rows".to_string(), size.rows.to_string()),
("columns".to_string(), size.columns.to_string())
])

Check warning on line 489 in src/uu/stty/src/stty.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/stty/src/stty.rs#L482-L489

Added lines #L482 - L489 were not covered by tests
)
);
}

#[cfg(any(target_os = "linux", target_os = "redox"))]
Expand All @@ -422,7 +497,13 @@
// so we get the underlying libc::termios struct to get that information.
let libc_termios: nix::libc::termios = termios.clone().into();
let line = libc_termios.c_line;
print!("line = {line};");
print!(
"{}",
get_message_with_args(
"stty-output-line",
HashMap::from([("line".to_string(), line.to_string())])
)
);

Check warning on line 506 in src/uu/stty/src/stty.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/stty/src/stty.rs#L500-L506

Added lines #L500 - L506 were not covered by tests
}

println!();
Expand Down Expand Up @@ -498,7 +579,7 @@

fn control_char_to_string(cc: nix::libc::cc_t) -> nix::Result<String> {
if cc == 0 {
return Ok("<undef>".to_string());
return Ok(get_message("stty-output-undef"));

Check warning on line 582 in src/uu/stty/src/stty.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/stty/src/stty.rs#L582

Added line #L582 was not covered by tests
}

let (meta_prefix, code) = if cc >= 0x80 {
Expand Down Expand Up @@ -535,9 +616,20 @@
);
}
println!(
"min = {}; time = {};",
termios.control_chars[SpecialCharacterIndices::VMIN as usize],
termios.control_chars[SpecialCharacterIndices::VTIME as usize]
"{}",
get_message_with_args(
"stty-output-min-time",
HashMap::from([
(
"min".to_string(),
termios.control_chars[SpecialCharacterIndices::VMIN as usize].to_string()
),
(
"time".to_string(),
termios.control_chars[SpecialCharacterIndices::VTIME as usize].to_string()
)
])

Check warning on line 631 in src/uu/stty/src/stty.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/stty/src/stty.rs#L619-L631

Added lines #L619 - L631 were not covered by tests
)
);
Ok(())
}
Expand Down Expand Up @@ -682,14 +774,18 @@
let ascii_num = if let Some(hex) = s.strip_prefix("0x") {
u32::from_str_radix(hex, 16).ok()
} else if let Some(octal) = s.strip_prefix("0") {
u32::from_str_radix(octal, 8).ok()
if octal.is_empty() {
Some(0)

Check warning on line 778 in src/uu/stty/src/stty.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/stty/src/stty.rs#L778

Added line #L778 was not covered by tests
} else {
u32::from_str_radix(octal, 8).ok()
}
} else {
s.parse::<u32>().ok()
};

if let Some(val) = ascii_num {
if val > 255 {
return Err(ControlCharMappingError::IntOutOfRange);
return Err(ControlCharMappingError::IntOutOfRange(s.to_string()));
} else {
return Ok(val as u8);
}
Expand All @@ -706,7 +802,7 @@
Ok((c.to_ascii_uppercase() as u8).wrapping_sub(b'@'))
}
(Some(c), None) => Ok(c as u8),
(Some(_), Some(_)) => Err(ControlCharMappingError::MultipleChars),
(Some(_), Some(_)) => Err(ControlCharMappingError::MultipleChars(s.to_string())),
_ => unreachable!("No arguments provided: must have been caught earlier"),
}
}
Expand All @@ -721,14 +817,14 @@
Arg::new(options::ALL)
.short('a')
.long(options::ALL)
.help("print all current settings in human-readable form")
.help(get_message("stty-option-all"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::SAVE)
.short('g')
.long(options::SAVE)
.help("print all current settings in a stty-readable form")
.help(get_message("stty-option-save"))
.action(ArgAction::SetTrue),
)
.arg(
Expand All @@ -737,13 +833,13 @@
.long(options::FILE)
.value_hint(clap::ValueHint::FilePath)
.value_name("DEVICE")
.help("open and use the specified DEVICE instead of stdin"),
.help(get_message("stty-option-file")),
)
.arg(
Arg::new(options::SETTINGS)
.action(ArgAction::Append)
.allow_hyphen_values(true)
.help("settings to change"),
.help(get_message("stty-option-settings")),
)
}

Expand Down
Loading
0