From a73ecd95e6fafd06e70e700805b9d089e921dabe Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 27 Jul 2025 13:09:45 +0900 Subject: [PATCH] uucore: adjust it too to use the translate macro --- src/uucore/src/lib/features/uptime.rs | 33 ++++++++++++--------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/uucore/src/lib/features/uptime.rs b/src/uucore/src/lib/features/uptime.rs index 141c3793c..38991a923 100644 --- a/src/uucore/src/lib/features/uptime.rs +++ b/src/uucore/src/lib/features/uptime.rs @@ -13,21 +13,20 @@ // 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 crate::translate; use chrono::Local; use libc::time_t; -use std::collections::HashMap; use thiserror::Error; #[derive(Debug, Error)] pub enum UptimeError { - #[error("{}", get_message("uptime-lib-error-system-uptime"))] + #[error("{}", translate!("uptime-lib-error-system-uptime"))] SystemUptime, - #[error("{}", get_message("uptime-lib-error-system-loadavg"))] + #[error("{}", translate!("uptime-lib-error-system-loadavg"))] SystemLoadavg, - #[error("{}", get_message("uptime-lib-error-windows-loadavg"))] + #[error("{}", translate!("uptime-lib-error-windows-loadavg"))] WindowsLoadavg, - #[error("{}", get_message("uptime-lib-error-boot-time"))] + #[error("{}", translate!("uptime-lib-error-boot-time"))] BootTime, } @@ -177,12 +176,10 @@ pub fn get_formatted_uptime(boot_time: Option) -> UResult { let up_hours = (up_secs - (up_days * 86400)) / 3600; let up_mins = (up_secs - (up_days * 86400) - (up_hours * 3600)) / 60; - Ok(get_message_with_args( + Ok(translate!( "uptime-format", - HashMap::from([ - ("days".to_string(), up_days.to_string()), - ("time".to_string(), format!("{up_hours:02}:{up_mins:02}")), - ]), + "days" => up_days, + "time" => format!("{up_hours:02}:{up_mins:02}") )) } @@ -310,9 +307,9 @@ pub fn get_nusers() -> usize { /// e.g. "0 users", "1 user", "2 users" #[inline] pub fn format_nusers(n: usize) -> String { - get_message_with_args( + translate!( "uptime-user-count", - HashMap::from([("count".to_string(), n.to_string())]), + "count" => n ) } @@ -372,13 +369,11 @@ pub fn get_loadavg() -> UResult<(f64, f64, f64)> { #[inline] pub fn get_formatted_loadavg() -> UResult { let loadavg = get_loadavg()?; - Ok(get_message_with_args( + Ok(translate!( "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)), - ]), + "avg1" => format!("{:.2}", loadavg.0), + "avg5" => format!("{:.2}", loadavg.1), + "avg15" => format!("{:.2}", loadavg.2), )) }