Skip to content

Commit 9812121

Browse files
mattsu2020sgmarz
authored andcommitted
refactor(uptime): use FluentArgs for loadavg formatting in get_formatted_loadavg
Refactored the `get_formatted_loadavg` function to explicitly build a `FluentArgs` struct with load average values formatted to two decimal places, then pass it to `crate::locale::get_message_with_args` instead of using the `translate!` macro inline. This improves argument handling for fluent localization, enhancing code structure and maintainability without altering functionality.
1 parent 4255a20 commit 9812121

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/uucore/src/lib/features/uptime.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,13 @@ pub fn get_loadavg() -> UResult<(f64, f64, f64)> {
421421
#[inline]
422422
pub fn get_formatted_loadavg() -> UResult<String> {
423423
let loadavg = get_loadavg()?;
424-
Ok(translate!(
424+
let mut args = fluent::FluentArgs::new();
425+
args.set("avg1", format!("{:.2}", loadavg.0));
426+
args.set("avg5", format!("{:.2}", loadavg.1));
427+
args.set("avg15", format!("{:.2}", loadavg.2));
428+
Ok(crate::locale::get_message_with_args(
425429
"uptime-lib-format-loadavg",
426-
"avg1" => format!("{:.2}", loadavg.0),
427-
"avg5" => format!("{:.2}", loadavg.1),
428-
"avg15" => format!("{:.2}", loadavg.2),
430+
args,
429431
))
430432
}
431433

0 commit comments

Comments
 (0)