Skip to content

Commit e68f734

Browse files
authored
Merge branch 'main' into stat-bigtime
2 parents 8428291 + 4a68e3d commit e68f734

File tree

251 files changed

+2946
-4434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

251 files changed

+2946
-4434
lines changed

Cargo.lock

Lines changed: 107 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/src/l10n.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,30 +66,29 @@ You can override the locale at runtime by running:
6666

6767
## 📥 Retrieving Messages
6868

69-
Two APIs are available:
69+
We have a single macro to handle translations.
70+
It can be used in two ways:
7071

71-
### `get_message(id: &str) -> String`
72+
### `translate!(id: &str) -> String`
7273

7374
Returns the message from the current locale bundle.
7475

7576
```
76-
let msg = get_message("id-greeting");
77+
let msg = translate!("id-greeting");
7778
```
7879

7980
If not found, falls back to `en-US`. If still missing, returns the ID itself.
8081

8182
---
8283

83-
### `get_message_with_args(id: &str, args: HashMap<String, String>) -> String`
84+
### `translate!(id: &str, args: key-value pairs) -> String`
8485

8586
Supports variable interpolation and pluralization.
8687

8788
```
88-
let msg = get_message_with_args(
89+
let msg = translate!(
8990
"error-io",
90-
HashMap::from([
91-
("error".to_string(), std::io::Error::last_os_error().to_string())
92-
])
91+
"error" => std::io::Error::last_os_error()
9392
);
9493
```
9594

fuzz/Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/arch/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ path = "src/arch.rs"
2121
platform-info = { workspace = true }
2222
clap = { workspace = true }
2323
uucore = { workspace = true }
24+
fluent = { workspace = true }
2425

2526
[[bin]]
2627
name = "arch"

src/uu/arch/src/arch.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ use platform_info::*;
77

88
use clap::Command;
99
use uucore::error::{UResult, USimpleError};
10-
use uucore::locale::get_message;
10+
use uucore::translate;
1111

1212
#[uucore::main]
1313
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
1414
uu_app().try_get_matches_from(args)?;
1515

1616
let uts =
17-
PlatformInfo::new().map_err(|_e| USimpleError::new(1, get_message("cannot-get-system")))?;
17+
PlatformInfo::new().map_err(|_e| USimpleError::new(1, translate!("cannot-get-system")))?;
1818

1919
println!("{}", uts.machine().to_string_lossy().trim());
2020
Ok(())
@@ -23,7 +23,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
2323
pub fn uu_app() -> Command {
2424
Command::new(uucore::util_name())
2525
.version(uucore::crate_version!())
26-
.about(get_message("arch-about"))
27-
.after_help(get_message("arch-after-help"))
26+
.about(translate!("arch-about"))
27+
.after_help(translate!("arch-after-help"))
2828
.infer_long_args(true)
2929
}

src/uu/base32/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ path = "src/base32.rs"
2020
[dependencies]
2121
clap = { workspace = true }
2222
uucore = { workspace = true, features = ["encoding"] }
23+
fluent = { workspace = true }
2324

2425
[[bin]]
2526
name = "base32"

src/uu/base32/src/base32.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
pub mod base_common;
77

88
use clap::Command;
9-
use uucore::{encoding::Format, error::UResult, locale::get_message};
9+
use uucore::{encoding::Format, error::UResult, translate};
1010

1111
#[uucore::main]
1212
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
@@ -23,7 +23,7 @@ pub fn uu_app() -> Command {
2323
}
2424

2525
fn get_info() -> (&'static str, &'static str) {
26-
let about: &'static str = Box::leak(get_message("base32-about").into_boxed_str());
27-
let usage: &'static str = Box::leak(get_message("base32-usage").into_boxed_str());
26+
let about: &'static str = Box::leak(translate!("base32-about").into_boxed_str());
27+
let usage: &'static str = Box::leak(translate!("base32-usage").into_boxed_str());
2828
(about, usage)
2929
}

src/uu/base32/src/base_common.rs

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// spell-checker:ignore hexupper lsbf msbf unpadded nopad aGVsbG8sIHdvcmxkIQ
77

88
use clap::{Arg, ArgAction, Command};
9-
use std::collections::HashMap;
109
use std::fs::File;
1110
use std::io::{self, ErrorKind, Read, Seek, SeekFrom};
1211
use std::path::{Path, PathBuf};
@@ -18,7 +17,7 @@ use uucore::encoding::{
1817
use uucore::encoding::{EncodingWrapper, SupportsFastDecodeAndEncode};
1918
use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
2019
use uucore::format_usage;
21-
use uucore::locale::{get_message, get_message_with_args};
20+
use uucore::translate;
2221

2322
pub const BASE_CMD_PARSE_ERROR: i32 = 1;
2423

@@ -52,10 +51,7 @@ impl Config {
5251
if let Some(extra_op) = values.next() {
5352
return Err(UUsageError::new(
5453
BASE_CMD_PARSE_ERROR,
55-
get_message_with_args(
56-
"base-common-extra-operand",
57-
HashMap::from([("operand".to_string(), extra_op.quote().to_string())]),
58-
),
54+
translate!("base-common-extra-operand", "operand" => extra_op.quote()),
5955
));
6056
}
6157

@@ -67,13 +63,7 @@ impl Config {
6763
if !path.exists() {
6864
return Err(USimpleError::new(
6965
BASE_CMD_PARSE_ERROR,
70-
get_message_with_args(
71-
"base-common-no-such-file",
72-
HashMap::from([(
73-
"file".to_string(),
74-
path.maybe_quote().to_string(),
75-
)]),
76-
),
66+
translate!("base-common-no-such-file", "file" => path.maybe_quote()),
7767
));
7868
}
7969

@@ -89,10 +79,7 @@ impl Config {
8979
num.parse::<usize>().map_err(|_| {
9080
USimpleError::new(
9181
BASE_CMD_PARSE_ERROR,
92-
get_message_with_args(
93-
"base-common-invalid-wrap-size",
94-
HashMap::from([("size".to_string(), num.quote().to_string())]),
95-
),
82+
translate!("base-common-invalid-wrap-size", "size" => num.quote()),
9683
)
9784
})
9885
})
@@ -128,15 +115,15 @@ pub fn base_app(about: &'static str, usage: &str) -> Command {
128115
.short('d')
129116
.visible_short_alias('D')
130117
.long(options::DECODE)
131-
.help(get_message("base-common-help-decode"))
118+
.help(translate!("base-common-help-decode"))
132119
.action(ArgAction::SetTrue)
133120
.overrides_with(options::DECODE),
134121
)
135122
.arg(
136123
Arg::new(options::IGNORE_GARBAGE)
137124
.short('i')
138125
.long(options::IGNORE_GARBAGE)
139-
.help(get_message("base-common-help-ignore-garbage"))
126+
.help(translate!("base-common-help-ignore-garbage"))
140127
.action(ArgAction::SetTrue)
141128
.overrides_with(options::IGNORE_GARBAGE),
142129
)
@@ -145,10 +132,7 @@ pub fn base_app(about: &'static str, usage: &str) -> Command {
145132
.short('w')
146133
.long(options::WRAP)
147134
.value_name("COLS")
148-
.help(get_message_with_args(
149-
"base-common-help-wrap",
150-
HashMap::from([("default".to_string(), WRAP_DEFAULT.to_string())]),
151-
))
135+
.help(translate!("base-common-help-wrap", "default" => WRAP_DEFAULT))
152136
.overrides_with(options::WRAP),
153137
)
154138
// "multiple" arguments are used to check whether there is more than one
@@ -830,10 +814,7 @@ fn format_read_error(kind: ErrorKind) -> String {
830814
}
831815
}
832816

833-
get_message_with_args(
834-
"base-common-read-error",
835-
HashMap::from([("error".to_string(), kind_string_capitalized)]),
836-
)
817+
translate!("base-common-read-error", "error" => kind_string_capitalized)
837818
}
838819

839820
#[cfg(test)]

src/uu/base64/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ path = "src/base64.rs"
2121
clap = { workspace = true }
2222
uucore = { workspace = true, features = ["encoding"] }
2323
uu_base32 = { workspace = true }
24+
fluent = { workspace = true }
2425

2526
[[bin]]
2627
name = "base64"

src/uu/base64/src/base64.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
use clap::Command;
77
use uu_base32::base_common;
8-
use uucore::{encoding::Format, error::UResult, locale::get_message};
8+
use uucore::translate;
9+
use uucore::{encoding::Format, error::UResult};
910

1011
#[uucore::main]
1112
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
@@ -22,7 +23,7 @@ pub fn uu_app() -> Command {
2223
}
2324

2425
fn get_info() -> (&'static str, &'static str) {
25-
let about: &'static str = Box::leak(get_message("base64-about").into_boxed_str());
26-
let usage: &'static str = Box::leak(get_message("base64-usage").into_boxed_str());
26+
let about: &'static str = Box::leak(translate!("base64-about").into_boxed_str());
27+
let usage: &'static str = Box::leak(translate!("base64-usage").into_boxed_str());
2728
(about, usage)
2829
}

0 commit comments

Comments
 (0)