mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 02:57:44 +00:00
Merge pull request #8092 from sylvestre/l10n-uptime
l10n: port uptime to translation + add french
This commit is contained in:
commit
069a43a65d
4 changed files with 120 additions and 31 deletions
|
@ -5,3 +5,37 @@ uptime-usage = uptime [OPTION]...
|
|||
uptime-about-musl-warning = Warning: When built with musl libc, the `uptime` utility may show '0 users'
|
||||
due to musl's stub implementation of utmpx functions. Boot time and load averages
|
||||
are still calculated using alternative mechanisms.
|
||||
|
||||
# Help messages
|
||||
uptime-help-since = system up since
|
||||
uptime-help-path = file to search boot time from
|
||||
|
||||
# Error messages
|
||||
uptime-error-io = couldn't get boot time: { $error }
|
||||
uptime-error-target-is-dir = couldn't get boot time: Is a directory
|
||||
uptime-error-target-is-fifo = couldn't get boot time: Illegal seek
|
||||
uptime-error-couldnt-get-boot-time = couldn't get boot time
|
||||
|
||||
# Output messages
|
||||
uptime-output-unknown-uptime = up ???? days ??:??,
|
||||
|
||||
uptime-user-count = { $count ->
|
||||
[one] 1 user
|
||||
*[other] { $count } users
|
||||
}
|
||||
|
||||
# Error messages
|
||||
uptime-lib-error-system-uptime = could not retrieve system uptime
|
||||
uptime-lib-error-system-loadavg = could not retrieve system load average
|
||||
uptime-lib-error-windows-loadavg = Windows does not have an equivalent to the load average on Unix-like systems
|
||||
uptime-lib-error-boot-time = boot time larger than current time
|
||||
|
||||
# Uptime formatting
|
||||
uptime-format = { $days ->
|
||||
[0] { $time }
|
||||
[one] { $days } day, { $time }
|
||||
*[other] { $days } days { $time }
|
||||
}
|
||||
|
||||
# Load average formatting
|
||||
uptime-lib-format-loadavg = load average: { $avg1 }, { $avg5 }, { $avg15 }
|
||||
|
|
41
src/uu/uptime/locales/fr-FR.ftl
Normal file
41
src/uu/uptime/locales/fr-FR.ftl
Normal file
|
@ -0,0 +1,41 @@
|
|||
uptime-about = Afficher l'heure actuelle, la durée pendant laquelle le système a été actif,
|
||||
le nombre d'utilisateurs sur le système, et le nombre moyen de tâches
|
||||
dans la file d'attente d'exécution au cours des 1, 5 et 15 dernières minutes.
|
||||
uptime-usage = uptime [OPTION]...
|
||||
uptime-about-musl-warning = Avertissement : Lorsque compilé avec musl libc, l'utilitaire `uptime` peut afficher '0 utilisateur'
|
||||
en raison de l'implémentation stub des fonctions utmpx de musl. L'heure de démarrage et les moyennes de charge
|
||||
sont toujours calculées en utilisant des mécanismes alternatifs.
|
||||
|
||||
# Messages d'aide
|
||||
uptime-help-since = système actif depuis
|
||||
uptime-help-path = fichier pour rechercher l'heure de démarrage
|
||||
|
||||
# Messages d'erreur
|
||||
uptime-error-io = impossible d'obtenir l'heure de démarrage : { $error }
|
||||
uptime-error-target-is-dir = impossible d'obtenir l'heure de démarrage : Est un répertoire
|
||||
uptime-error-target-is-fifo = impossible d'obtenir l'heure de démarrage : Recherche illégale
|
||||
uptime-error-couldnt-get-boot-time = impossible d'obtenir l'heure de démarrage
|
||||
|
||||
# Messages de sortie
|
||||
uptime-output-unknown-uptime = actif ???? jours ??:??,
|
||||
|
||||
uptime-user-count = { $count ->
|
||||
[one] 1 utilisateur
|
||||
*[other] { $count } utilisateurs
|
||||
}
|
||||
|
||||
# Messages d'erreur
|
||||
uptime-lib-error-system-uptime = impossible de récupérer la durée de fonctionnement du système
|
||||
uptime-lib-error-system-loadavg = impossible de récupérer la charge moyenne du système
|
||||
uptime-lib-error-windows-loadavg = Windows n'a pas d'équivalent à la charge moyenne des systèmes de type Unix
|
||||
uptime-lib-error-boot-time = heure de démarrage supérieure à l'heure actuelle
|
||||
|
||||
# Formatage de la durée de fonctionnement
|
||||
uptime-format = { $days ->
|
||||
[0] { $time }
|
||||
[one] { $days } jour, { $time }
|
||||
*[other] { $days } jours { $time }
|
||||
}
|
||||
|
||||
# Formatage de la charge moyenne
|
||||
uptime-lib-format-loadavg = charge moyenne : { $avg1 }, { $avg5 }, { $avg15 }
|
|
@ -3,9 +3,10 @@
|
|||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
|
||||
// spell-checker:ignore getloadavg behaviour loadavg uptime upsecs updays upmins uphours boottime nusers utmpxname gettime clockid
|
||||
// spell-checker:ignore getloadavg behaviour loadavg uptime upsecs updays upmins uphours boottime nusers utmpxname gettime clockid couldnt
|
||||
|
||||
use chrono::{Local, TimeZone, Utc};
|
||||
use std::collections::HashMap;
|
||||
#[cfg(unix)]
|
||||
use std::ffi::OsString;
|
||||
use std::io;
|
||||
|
@ -17,8 +18,8 @@ use uucore::uptime::*;
|
|||
use clap::{Arg, ArgAction, Command, ValueHint, builder::ValueParser};
|
||||
|
||||
use uucore::format_usage;
|
||||
use uucore::locale::get_message;
|
||||
|
||||
use uucore::locale::{get_message, get_message_with_args};
|
||||
#[cfg(unix)]
|
||||
#[cfg(not(target_os = "openbsd"))]
|
||||
use uucore::utmpx::*;
|
||||
|
@ -31,11 +32,11 @@ pub mod options {
|
|||
#[derive(Debug, Error)]
|
||||
pub enum UptimeError {
|
||||
// io::Error wrapper
|
||||
#[error("couldn't get boot time: {0}")]
|
||||
#[error("{}", get_message_with_args("uptime-error-io", HashMap::from([("error".to_string(), format!("{}", .0))])))]
|
||||
IoErr(#[from] io::Error),
|
||||
#[error("couldn't get boot time: Is a directory")]
|
||||
#[error("{}", get_message("uptime-error-target-is-dir"))]
|
||||
TargetIsDir,
|
||||
#[error("couldn't get boot time: Illegal seek")]
|
||||
#[error("{}", get_message("uptime-error-target-is-fifo"))]
|
||||
TargetIsFifo,
|
||||
}
|
||||
|
||||
|
@ -78,13 +79,13 @@ pub fn uu_app() -> Command {
|
|||
Arg::new(options::SINCE)
|
||||
.short('s')
|
||||
.long(options::SINCE)
|
||||
.help("system up since")
|
||||
.help(get_message("uptime-help-since"))
|
||||
.action(ArgAction::SetTrue),
|
||||
);
|
||||
#[cfg(unix)]
|
||||
cmd.arg(
|
||||
Arg::new(options::PATH)
|
||||
.help("file to search boot time from")
|
||||
.help(get_message("uptime-help-path"))
|
||||
.action(ArgAction::Set)
|
||||
.num_args(0..=1)
|
||||
.value_parser(ValueParser::os_string())
|
||||
|
@ -130,9 +131,9 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
|
|||
let bytes = file_path.as_os_str().as_bytes();
|
||||
|
||||
if bytes[bytes.len() - 1] != b'x' {
|
||||
show_error!("couldn't get boot time");
|
||||
show_error!("{}", get_message("uptime-error-couldnt-get-boot-time"));
|
||||
print_time();
|
||||
print!("up ???? days ??:??,");
|
||||
print!("{}", get_message("uptime-output-unknown-uptime"));
|
||||
print_nusers(Some(0));
|
||||
print_loadavg();
|
||||
set_exit_code(1);
|
||||
|
@ -142,7 +143,7 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
|
|||
|
||||
if non_fatal_error {
|
||||
print_time();
|
||||
print!("up ???? days ??:??,");
|
||||
print!("{}", get_message("uptime-output-unknown-uptime"));
|
||||
print_nusers(Some(0));
|
||||
print_loadavg();
|
||||
return Ok(());
|
||||
|
@ -157,10 +158,10 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
|
|||
if let Some(time) = boot_time {
|
||||
print_uptime(Some(time))?;
|
||||
} else {
|
||||
show_error!("couldn't get boot time");
|
||||
show_error!("{}", get_message("uptime-error-couldnt-get-boot-time"));
|
||||
set_exit_code(1);
|
||||
|
||||
print!("up ???? days ??:??,");
|
||||
print!("{}", get_message("uptime-output-unknown-uptime"));
|
||||
}
|
||||
user_count = count;
|
||||
}
|
||||
|
@ -171,10 +172,10 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
|
|||
if upsecs >= 0 {
|
||||
print_uptime(Some(upsecs))?;
|
||||
} else {
|
||||
show_error!("couldn't get boot time");
|
||||
show_error!("{}", get_message("uptime-error-couldnt-get-boot-time"));
|
||||
set_exit_code(1);
|
||||
|
||||
print!("up ???? days ??:??,");
|
||||
print!("{}", get_message("uptime-output-unknown-uptime"));
|
||||
}
|
||||
user_count = get_nusers(file_path.to_str().expect("invalid utmp path file"));
|
||||
}
|
||||
|
|
|
@ -13,19 +13,21 @@
|
|||
// See https://github.com/uutils/coreutils/pull/7289 for discussion.
|
||||
|
||||
use crate::error::{UError, UResult};
|
||||
use crate::locale::{get_message, get_message_with_args};
|
||||
use chrono::Local;
|
||||
use libc::time_t;
|
||||
use std::collections::HashMap;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum UptimeError {
|
||||
#[error("could not retrieve system uptime")]
|
||||
#[error("{}", get_message("uptime-lib-error-system-uptime"))]
|
||||
SystemUptime,
|
||||
#[error("could not retrieve system load average")]
|
||||
#[error("{}", get_message("uptime-lib-error-system-loadavg"))]
|
||||
SystemLoadavg,
|
||||
#[error("Windows does not have an equivalent to the load average on Unix-like systems")]
|
||||
#[error("{}", get_message("uptime-lib-error-windows-loadavg"))]
|
||||
WindowsLoadavg,
|
||||
#[error("boot time larger than current time")]
|
||||
#[error("{}", get_message("uptime-lib-error-boot-time"))]
|
||||
BootTime,
|
||||
}
|
||||
|
||||
|
@ -174,11 +176,14 @@ pub fn get_formatted_uptime(boot_time: Option<time_t>) -> UResult<String> {
|
|||
let up_days = up_secs / 86400;
|
||||
let up_hours = (up_secs - (up_days * 86400)) / 3600;
|
||||
let up_mins = (up_secs - (up_days * 86400) - (up_hours * 3600)) / 60;
|
||||
match up_days.cmp(&1) {
|
||||
std::cmp::Ordering::Equal => Ok(format!("{up_days:1} day, {up_hours:2}:{up_mins:02}")),
|
||||
std::cmp::Ordering::Greater => Ok(format!("{up_days:1} days {up_hours:2}:{up_mins:02}")),
|
||||
_ => Ok(format!("{up_hours:2}:{up_mins:02}")),
|
||||
}
|
||||
|
||||
Ok(get_message_with_args(
|
||||
"uptime-format",
|
||||
HashMap::from([
|
||||
("days".to_string(), up_days.to_string()),
|
||||
("time".to_string(), format!("{up_hours:02}:{up_mins:02}")),
|
||||
]),
|
||||
))
|
||||
}
|
||||
|
||||
/// Get the number of users currently logged in
|
||||
|
@ -305,11 +310,10 @@ pub fn get_nusers() -> usize {
|
|||
/// e.g. "0 users", "1 user", "2 users"
|
||||
#[inline]
|
||||
pub fn format_nusers(n: usize) -> String {
|
||||
if n == 1 {
|
||||
String::from("1 user")
|
||||
} else {
|
||||
format!("{n} users")
|
||||
}
|
||||
get_message_with_args(
|
||||
"uptime-user-count",
|
||||
HashMap::from([("count".to_string(), n.to_string())]),
|
||||
)
|
||||
}
|
||||
|
||||
/// Get the number of users currently logged in in a human-readable format
|
||||
|
@ -368,18 +372,27 @@ pub fn get_loadavg() -> UResult<(f64, f64, f64)> {
|
|||
#[inline]
|
||||
pub fn get_formatted_loadavg() -> UResult<String> {
|
||||
let loadavg = get_loadavg()?;
|
||||
Ok(format!(
|
||||
"load average: {:.2}, {:.2}, {:.2}",
|
||||
loadavg.0, loadavg.1, loadavg.2
|
||||
Ok(get_message_with_args(
|
||||
"uptime-lib-format-loadavg",
|
||||
HashMap::from([
|
||||
("avg1".to_string(), format!("{:.2}", loadavg.0)),
|
||||
("avg5".to_string(), format!("{:.2}", loadavg.1)),
|
||||
("avg15".to_string(), format!("{:.2}", loadavg.2)),
|
||||
]),
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::locale;
|
||||
|
||||
#[test]
|
||||
fn test_format_nusers() {
|
||||
unsafe {
|
||||
std::env::set_var("LANG", "en_US.UTF-8");
|
||||
}
|
||||
let _ = locale::setup_localization("uptime");
|
||||
assert_eq!("0 users", format_nusers(0));
|
||||
assert_eq!("1 user", format_nusers(1));
|
||||
assert_eq!("2 users", format_nusers(2));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue