diff --git a/Cargo.lock b/Cargo.lock index e23074ee5d7..67e1629ebe5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2945,6 +2945,7 @@ name = "uu_arch" version = "0.1.0" dependencies = [ "clap", + "fluent", "platform-info", "uucore", ] @@ -2954,6 +2955,7 @@ name = "uu_base32" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -2962,6 +2964,7 @@ name = "uu_base64" version = "0.1.0" dependencies = [ "clap", + "fluent", "uu_base32", "uucore", ] @@ -2971,6 +2974,7 @@ name = "uu_basename" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -2979,6 +2983,7 @@ name = "uu_basenc" version = "0.1.0" dependencies = [ "clap", + "fluent", "uu_base32", "uucore", ] @@ -2988,6 +2993,7 @@ name = "uu_cat" version = "0.1.0" dependencies = [ "clap", + "fluent", "memchr", "nix", "tempfile", @@ -3002,6 +3008,7 @@ name = "uu_chcon" version = "0.1.0" dependencies = [ "clap", + "fluent", "fts-sys", "libc", "selinux", @@ -3014,6 +3021,7 @@ name = "uu_chgrp" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3022,6 +3030,7 @@ name = "uu_chmod" version = "0.1.0" dependencies = [ "clap", + "fluent", "thiserror 2.0.12", "uucore", ] @@ -3031,6 +3040,7 @@ name = "uu_chown" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3039,6 +3049,7 @@ name = "uu_chroot" version = "0.1.0" dependencies = [ "clap", + "fluent", "thiserror 2.0.12", "uucore", ] @@ -3048,6 +3059,7 @@ name = "uu_cksum" version = "0.1.0" dependencies = [ "clap", + "fluent", "hex", "uucore", ] @@ -3057,6 +3069,7 @@ name = "uu_comm" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3067,6 +3080,7 @@ dependencies = [ "clap", "exacl", "filetime", + "fluent", "indicatif", "libc", "linux-raw-sys 0.10.0", @@ -3082,6 +3096,7 @@ name = "uu_csplit" version = "0.1.0" dependencies = [ "clap", + "fluent", "regex", "thiserror 2.0.12", "uucore", @@ -3093,6 +3108,7 @@ version = "0.1.0" dependencies = [ "bstr", "clap", + "fluent", "memchr", "uucore", ] @@ -3103,6 +3119,7 @@ version = "0.1.0" dependencies = [ "chrono", "clap", + "fluent", "jiff", "libc", "parse_datetime", @@ -3115,6 +3132,7 @@ name = "uu_dd" version = "0.1.0" dependencies = [ "clap", + "fluent", "gcd", "libc", "nix", @@ -3128,6 +3146,7 @@ name = "uu_df" version = "0.1.0" dependencies = [ "clap", + "fluent", "tempfile", "thiserror 2.0.12", "unicode-width 0.2.1", @@ -3148,6 +3167,7 @@ name = "uu_dircolors" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3156,6 +3176,7 @@ name = "uu_dirname" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3164,6 +3185,7 @@ name = "uu_du" version = "0.1.0" dependencies = [ "clap", + "fluent", "glob", "thiserror 2.0.12", "uucore", @@ -3175,6 +3197,7 @@ name = "uu_echo" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3183,6 +3206,7 @@ name = "uu_env" version = "0.1.0" dependencies = [ "clap", + "fluent", "nix", "rust-ini", "thiserror 2.0.12", @@ -3194,6 +3218,7 @@ name = "uu_expand" version = "0.1.0" dependencies = [ "clap", + "fluent", "thiserror 2.0.12", "unicode-width 0.2.1", "uucore", @@ -3204,6 +3229,7 @@ name = "uu_expr" version = "0.1.0" dependencies = [ "clap", + "fluent", "num-bigint", "num-traits", "onig", @@ -3216,6 +3242,7 @@ name = "uu_factor" version = "0.1.0" dependencies = [ "clap", + "fluent", "num-bigint", "num-prime", "num-traits", @@ -3238,6 +3265,7 @@ name = "uu_false" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3246,6 +3274,7 @@ name = "uu_fmt" version = "0.1.0" dependencies = [ "clap", + "fluent", "thiserror 2.0.12", "unicode-width 0.2.1", "uucore", @@ -3256,6 +3285,7 @@ name = "uu_fold" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3264,6 +3294,7 @@ name = "uu_groups" version = "0.1.0" dependencies = [ "clap", + "fluent", "thiserror 2.0.12", "uucore", ] @@ -3273,6 +3304,7 @@ name = "uu_hashsum" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3281,6 +3313,7 @@ name = "uu_head" version = "0.1.0" dependencies = [ "clap", + "fluent", "memchr", "thiserror 2.0.12", "uucore", @@ -3291,6 +3324,7 @@ name = "uu_hostid" version = "0.1.0" dependencies = [ "clap", + "fluent", "libc", "uucore", ] @@ -3301,6 +3335,7 @@ version = "0.1.0" dependencies = [ "clap", "dns-lookup", + "fluent", "hostname", "uucore", "windows-sys 0.60.2", @@ -3311,6 +3346,7 @@ name = "uu_id" version = "0.1.0" dependencies = [ "clap", + "fluent", "selinux", "uucore", ] @@ -3322,6 +3358,7 @@ dependencies = [ "clap", "file_diff", "filetime", + "fluent", "thiserror 2.0.12", "uucore", ] @@ -3331,6 +3368,7 @@ name = "uu_join" version = "0.1.0" dependencies = [ "clap", + "fluent", "memchr", "thiserror 2.0.12", "uucore", @@ -3341,6 +3379,7 @@ name = "uu_kill" version = "0.1.0" dependencies = [ "clap", + "fluent", "nix", "uucore", ] @@ -3350,6 +3389,7 @@ name = "uu_link" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3358,6 +3398,7 @@ name = "uu_ln" version = "0.1.0" dependencies = [ "clap", + "fluent", "thiserror 2.0.12", "uucore", ] @@ -3367,6 +3408,7 @@ name = "uu_logname" version = "0.1.0" dependencies = [ "clap", + "fluent", "libc", "uucore", ] @@ -3377,6 +3419,7 @@ version = "0.1.0" dependencies = [ "ansi-width", "clap", + "fluent", "glob", "hostname", "lscolors", @@ -3392,6 +3435,7 @@ name = "uu_mkdir" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3400,6 +3444,7 @@ name = "uu_mkfifo" version = "0.1.0" dependencies = [ "clap", + "fluent", "libc", "uucore", ] @@ -3409,6 +3454,7 @@ name = "uu_mknod" version = "0.1.0" dependencies = [ "clap", + "fluent", "libc", "uucore", ] @@ -3418,6 +3464,7 @@ name = "uu_mktemp" version = "0.1.0" dependencies = [ "clap", + "fluent", "rand 0.9.2", "tempfile", "thiserror 2.0.12", @@ -3430,6 +3477,7 @@ version = "0.1.0" dependencies = [ "clap", "crossterm", + "fluent", "nix", "tempfile", "uucore", @@ -3440,6 +3488,7 @@ name = "uu_mv" version = "0.1.0" dependencies = [ "clap", + "fluent", "fs_extra", "indicatif", "libc", @@ -3453,6 +3502,7 @@ name = "uu_nice" version = "0.1.0" dependencies = [ "clap", + "fluent", "libc", "nix", "uucore", @@ -3463,6 +3513,7 @@ name = "uu_nl" version = "0.1.0" dependencies = [ "clap", + "fluent", "regex", "uucore", ] @@ -3472,6 +3523,7 @@ name = "uu_nohup" version = "0.1.0" dependencies = [ "clap", + "fluent", "libc", "thiserror 2.0.12", "uucore", @@ -3482,6 +3534,7 @@ name = "uu_nproc" version = "0.1.0" dependencies = [ "clap", + "fluent", "libc", "uucore", ] @@ -3491,6 +3544,7 @@ name = "uu_numfmt" version = "0.1.0" dependencies = [ "clap", + "fluent", "thiserror 2.0.12", "uucore", ] @@ -3501,6 +3555,7 @@ version = "0.1.0" dependencies = [ "byteorder", "clap", + "fluent", "half", "uucore", ] @@ -3510,6 +3565,7 @@ name = "uu_paste" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3518,6 +3574,7 @@ name = "uu_pathchk" version = "0.1.0" dependencies = [ "clap", + "fluent", "libc", "uucore", ] @@ -3527,6 +3584,7 @@ name = "uu_pinky" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3536,6 +3594,7 @@ version = "0.1.0" dependencies = [ "chrono", "clap", + "fluent", "itertools 0.14.0", "regex", "thiserror 2.0.12", @@ -3547,6 +3606,7 @@ name = "uu_printenv" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3555,6 +3615,7 @@ name = "uu_printf" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3563,6 +3624,7 @@ name = "uu_ptx" version = "0.1.0" dependencies = [ "clap", + "fluent", "regex", "thiserror 2.0.12", "uucore", @@ -3573,6 +3635,7 @@ name = "uu_pwd" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3581,6 +3644,7 @@ name = "uu_readlink" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3589,6 +3653,7 @@ name = "uu_realpath" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3597,6 +3662,7 @@ name = "uu_rm" version = "0.1.0" dependencies = [ "clap", + "fluent", "libc", "thiserror 2.0.12", "uucore", @@ -3608,6 +3674,7 @@ name = "uu_rmdir" version = "0.1.0" dependencies = [ "clap", + "fluent", "libc", "uucore", ] @@ -3617,6 +3684,7 @@ name = "uu_runcon" version = "0.1.0" dependencies = [ "clap", + "fluent", "libc", "selinux", "thiserror 2.0.12", @@ -3629,6 +3697,7 @@ version = "0.1.0" dependencies = [ "bigdecimal", "clap", + "fluent", "num-bigint", "num-traits", "thiserror 2.0.12", @@ -3640,6 +3709,7 @@ name = "uu_shred" version = "0.1.0" dependencies = [ "clap", + "fluent", "libc", "rand 0.9.2", "uucore", @@ -3650,6 +3720,7 @@ name = "uu_shuf" version = "0.1.0" dependencies = [ "clap", + "fluent", "rand 0.9.2", "rand_core 0.9.3", "uucore", @@ -3660,6 +3731,7 @@ name = "uu_sleep" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3672,6 +3744,7 @@ dependencies = [ "clap", "compare", "ctrlc", + "fluent", "fnv", "itertools 0.14.0", "memchr", @@ -3690,6 +3763,7 @@ name = "uu_split" version = "0.1.0" dependencies = [ "clap", + "fluent", "memchr", "thiserror 2.0.12", "uucore", @@ -3701,6 +3775,7 @@ version = "0.1.0" dependencies = [ "chrono", "clap", + "fluent", "thiserror 2.0.12", "uucore", ] @@ -3710,6 +3785,7 @@ name = "uu_stdbuf" version = "0.1.0" dependencies = [ "clap", + "fluent", "tempfile", "thiserror 2.0.12", "uu_stdbuf_libstdbuf", @@ -3729,6 +3805,7 @@ name = "uu_stty" version = "0.1.0" dependencies = [ "clap", + "fluent", "nix", "uucore", ] @@ -3738,6 +3815,7 @@ name = "uu_sum" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3746,6 +3824,7 @@ name = "uu_sync" version = "0.1.0" dependencies = [ "clap", + "fluent", "nix", "uucore", "windows-sys 0.60.2", @@ -3756,6 +3835,7 @@ name = "uu_tac" version = "0.1.0" dependencies = [ "clap", + "fluent", "memchr", "memmap2", "regex", @@ -3768,6 +3848,7 @@ name = "uu_tail" version = "0.1.0" dependencies = [ "clap", + "fluent", "libc", "memchr", "notify", @@ -3783,6 +3864,7 @@ name = "uu_tee" version = "0.1.0" dependencies = [ "clap", + "fluent", "nix", "uucore", ] @@ -3792,6 +3874,7 @@ name = "uu_test" version = "0.1.0" dependencies = [ "clap", + "fluent", "libc", "thiserror 2.0.12", "uucore", @@ -3802,6 +3885,7 @@ name = "uu_timeout" version = "0.1.0" dependencies = [ "clap", + "fluent", "libc", "nix", "uucore", @@ -3814,6 +3898,7 @@ dependencies = [ "chrono", "clap", "filetime", + "fluent", "parse_datetime", "thiserror 2.0.12", "uucore", @@ -3825,6 +3910,7 @@ name = "uu_tr" version = "0.1.0" dependencies = [ "clap", + "fluent", "nom 8.0.0", "uucore", ] @@ -3834,6 +3920,7 @@ name = "uu_true" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3842,6 +3929,7 @@ name = "uu_truncate" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3850,6 +3938,7 @@ name = "uu_tsort" version = "0.1.0" dependencies = [ "clap", + "fluent", "thiserror 2.0.12", "uucore", ] @@ -3859,6 +3948,7 @@ name = "uu_tty" version = "0.1.0" dependencies = [ "clap", + "fluent", "nix", "uucore", ] @@ -3868,6 +3958,7 @@ name = "uu_uname" version = "0.1.0" dependencies = [ "clap", + "fluent", "platform-info", "uucore", ] @@ -3877,6 +3968,7 @@ name = "uu_unexpand" version = "0.1.0" dependencies = [ "clap", + "fluent", "thiserror 2.0.12", "unicode-width 0.2.1", "uucore", @@ -3887,6 +3979,7 @@ name = "uu_uniq" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3895,6 +3988,7 @@ name = "uu_unlink" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3904,6 +3998,7 @@ version = "0.1.0" dependencies = [ "chrono", "clap", + "fluent", "thiserror 2.0.12", "utmp-classic", "uucore", @@ -3914,6 +4009,7 @@ name = "uu_users" version = "0.1.0" dependencies = [ "clap", + "fluent", "utmp-classic", "uucore", ] @@ -3933,6 +4029,7 @@ version = "0.1.0" dependencies = [ "bytecount", "clap", + "fluent", "libc", "nix", "thiserror 2.0.12", @@ -3945,6 +4042,7 @@ name = "uu_who" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -3953,6 +4051,7 @@ name = "uu_whoami" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", "windows-sys 0.60.2", ] @@ -3962,6 +4061,7 @@ name = "uu_yes" version = "0.1.0" dependencies = [ "clap", + "fluent", "itertools 0.14.0", "nix", "uucore", diff --git a/docs/src/l10n.md b/docs/src/l10n.md index 7f606a0b1e5..ec9c1db03c1 100644 --- a/docs/src/l10n.md +++ b/docs/src/l10n.md @@ -66,30 +66,29 @@ You can override the locale at runtime by running: ## 📥 Retrieving Messages -Two APIs are available: +We have a single macro to handle translations. +It can be used in two ways: -### `get_message(id: &str) -> String` +### `translate!(id: &str) -> String` Returns the message from the current locale bundle. ``` - let msg = get_message("id-greeting"); + let msg = translate!("id-greeting"); ``` If not found, falls back to `en-US`. If still missing, returns the ID itself. --- -### `get_message_with_args(id: &str, args: HashMap) -> String` +### `translate!(id: &str, args: key-value pairs) -> String` Supports variable interpolation and pluralization. ``` - let msg = get_message_with_args( + let msg = translate!( "error-io", - HashMap::from([ - ("error".to_string(), std::io::Error::last_os_error().to_string()) - ]) + "error" => std::io::Error::last_os_error() ); ``` diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 21ed1dbee70..c69adf67440 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -1435,6 +1435,7 @@ name = "uu_cksum" version = "0.1.0" dependencies = [ "clap", + "fluent", "hex", "uucore", ] @@ -1445,6 +1446,7 @@ version = "0.1.0" dependencies = [ "bstr", "clap", + "fluent", "memchr", "uucore", ] @@ -1455,6 +1457,7 @@ version = "0.1.0" dependencies = [ "chrono", "clap", + "fluent", "jiff", "libc", "parse_datetime", @@ -1467,6 +1470,7 @@ name = "uu_echo" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -1475,6 +1479,7 @@ name = "uu_env" version = "0.1.0" dependencies = [ "clap", + "fluent", "nix", "rust-ini", "thiserror", @@ -1486,6 +1491,7 @@ name = "uu_expr" version = "0.1.0" dependencies = [ "clap", + "fluent", "num-bigint", "num-traits", "onig", @@ -1498,6 +1504,7 @@ name = "uu_printf" version = "0.1.0" dependencies = [ "clap", + "fluent", "uucore", ] @@ -1507,6 +1514,7 @@ version = "0.1.0" dependencies = [ "bigdecimal", "clap", + "fluent", "num-bigint", "num-traits", "thiserror", @@ -1522,6 +1530,7 @@ dependencies = [ "clap", "compare", "ctrlc", + "fluent", "fnv", "itertools", "memchr", @@ -1540,6 +1549,7 @@ name = "uu_split" version = "0.1.0" dependencies = [ "clap", + "fluent", "memchr", "thiserror", "uucore", @@ -1550,6 +1560,7 @@ name = "uu_test" version = "0.1.0" dependencies = [ "clap", + "fluent", "libc", "thiserror", "uucore", @@ -1560,6 +1571,7 @@ name = "uu_tr" version = "0.1.0" dependencies = [ "clap", + "fluent", "nom", "uucore", ] @@ -1570,6 +1582,7 @@ version = "0.1.0" dependencies = [ "bytecount", "clap", + "fluent", "libc", "nix", "thiserror", diff --git a/src/uu/arch/Cargo.toml b/src/uu/arch/Cargo.toml index 611aa6845cf..39a2410baae 100644 --- a/src/uu/arch/Cargo.toml +++ b/src/uu/arch/Cargo.toml @@ -21,6 +21,7 @@ path = "src/arch.rs" platform-info = { workspace = true } clap = { workspace = true } uucore = { workspace = true } +fluent = { workspace = true } [[bin]] name = "arch" diff --git a/src/uu/arch/src/arch.rs b/src/uu/arch/src/arch.rs index aad79b430d1..29ad9d273c9 100644 --- a/src/uu/arch/src/arch.rs +++ b/src/uu/arch/src/arch.rs @@ -7,14 +7,14 @@ use platform_info::*; use clap::Command; use uucore::error::{UResult, USimpleError}; -use uucore::locale::get_message; +use uucore::translate; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { uu_app().try_get_matches_from(args)?; let uts = - PlatformInfo::new().map_err(|_e| USimpleError::new(1, get_message("cannot-get-system")))?; + PlatformInfo::new().map_err(|_e| USimpleError::new(1, translate!("cannot-get-system")))?; println!("{}", uts.machine().to_string_lossy().trim()); Ok(()) @@ -23,7 +23,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uu_app() -> Command { Command::new(uucore::util_name()) .version(uucore::crate_version!()) - .about(get_message("arch-about")) - .after_help(get_message("arch-after-help")) + .about(translate!("arch-about")) + .after_help(translate!("arch-after-help")) .infer_long_args(true) } diff --git a/src/uu/base32/Cargo.toml b/src/uu/base32/Cargo.toml index 42421311c0e..2318911b517 100644 --- a/src/uu/base32/Cargo.toml +++ b/src/uu/base32/Cargo.toml @@ -20,6 +20,7 @@ path = "src/base32.rs" [dependencies] clap = { workspace = true } uucore = { workspace = true, features = ["encoding"] } +fluent = { workspace = true } [[bin]] name = "base32" diff --git a/src/uu/base32/src/base32.rs b/src/uu/base32/src/base32.rs index 37bf01e3219..c88caa651b3 100644 --- a/src/uu/base32/src/base32.rs +++ b/src/uu/base32/src/base32.rs @@ -6,7 +6,7 @@ pub mod base_common; use clap::Command; -use uucore::{encoding::Format, error::UResult, locale::get_message}; +use uucore::{encoding::Format, error::UResult, translate}; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { @@ -23,7 +23,7 @@ pub fn uu_app() -> Command { } fn get_info() -> (&'static str, &'static str) { - let about: &'static str = Box::leak(get_message("base32-about").into_boxed_str()); - let usage: &'static str = Box::leak(get_message("base32-usage").into_boxed_str()); + let about: &'static str = Box::leak(translate!("base32-about").into_boxed_str()); + let usage: &'static str = Box::leak(translate!("base32-usage").into_boxed_str()); (about, usage) } diff --git a/src/uu/base32/src/base_common.rs b/src/uu/base32/src/base_common.rs index 9d0c69688cf..b7d1124ac1e 100644 --- a/src/uu/base32/src/base_common.rs +++ b/src/uu/base32/src/base_common.rs @@ -6,7 +6,6 @@ // spell-checker:ignore hexupper lsbf msbf unpadded nopad aGVsbG8sIHdvcmxkIQ use clap::{Arg, ArgAction, Command}; -use std::collections::HashMap; use std::fs::File; use std::io::{self, ErrorKind, Read, Seek, SeekFrom}; use std::path::{Path, PathBuf}; @@ -18,7 +17,7 @@ use uucore::encoding::{ use uucore::encoding::{EncodingWrapper, SupportsFastDecodeAndEncode}; use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; use uucore::format_usage; -use uucore::locale::{get_message, get_message_with_args}; +use uucore::translate; pub const BASE_CMD_PARSE_ERROR: i32 = 1; @@ -52,10 +51,7 @@ impl Config { if let Some(extra_op) = values.next() { return Err(UUsageError::new( BASE_CMD_PARSE_ERROR, - get_message_with_args( - "base-common-extra-operand", - HashMap::from([("operand".to_string(), extra_op.quote().to_string())]), - ), + translate!("base-common-extra-operand", "operand" => extra_op.quote()), )); } @@ -67,13 +63,7 @@ impl Config { if !path.exists() { return Err(USimpleError::new( BASE_CMD_PARSE_ERROR, - get_message_with_args( - "base-common-no-such-file", - HashMap::from([( - "file".to_string(), - path.maybe_quote().to_string(), - )]), - ), + translate!("base-common-no-such-file", "file" => path.maybe_quote()), )); } @@ -89,10 +79,7 @@ impl Config { num.parse::().map_err(|_| { USimpleError::new( BASE_CMD_PARSE_ERROR, - get_message_with_args( - "base-common-invalid-wrap-size", - HashMap::from([("size".to_string(), num.quote().to_string())]), - ), + translate!("base-common-invalid-wrap-size", "size" => num.quote()), ) }) }) @@ -128,7 +115,7 @@ pub fn base_app(about: &'static str, usage: &str) -> Command { .short('d') .visible_short_alias('D') .long(options::DECODE) - .help(get_message("base-common-help-decode")) + .help(translate!("base-common-help-decode")) .action(ArgAction::SetTrue) .overrides_with(options::DECODE), ) @@ -136,7 +123,7 @@ pub fn base_app(about: &'static str, usage: &str) -> Command { Arg::new(options::IGNORE_GARBAGE) .short('i') .long(options::IGNORE_GARBAGE) - .help(get_message("base-common-help-ignore-garbage")) + .help(translate!("base-common-help-ignore-garbage")) .action(ArgAction::SetTrue) .overrides_with(options::IGNORE_GARBAGE), ) @@ -145,10 +132,7 @@ pub fn base_app(about: &'static str, usage: &str) -> Command { .short('w') .long(options::WRAP) .value_name("COLS") - .help(get_message_with_args( - "base-common-help-wrap", - HashMap::from([("default".to_string(), WRAP_DEFAULT.to_string())]), - )) + .help(translate!("base-common-help-wrap", "default" => WRAP_DEFAULT)) .overrides_with(options::WRAP), ) // "multiple" arguments are used to check whether there is more than one @@ -830,10 +814,7 @@ fn format_read_error(kind: ErrorKind) -> String { } } - get_message_with_args( - "base-common-read-error", - HashMap::from([("error".to_string(), kind_string_capitalized)]), - ) + translate!("base-common-read-error", "error" => kind_string_capitalized) } #[cfg(test)] diff --git a/src/uu/base64/Cargo.toml b/src/uu/base64/Cargo.toml index aa899f1a1e6..8226b5877f5 100644 --- a/src/uu/base64/Cargo.toml +++ b/src/uu/base64/Cargo.toml @@ -21,6 +21,7 @@ path = "src/base64.rs" clap = { workspace = true } uucore = { workspace = true, features = ["encoding"] } uu_base32 = { workspace = true } +fluent = { workspace = true } [[bin]] name = "base64" diff --git a/src/uu/base64/src/base64.rs b/src/uu/base64/src/base64.rs index cd3ab66bded..854fd91820b 100644 --- a/src/uu/base64/src/base64.rs +++ b/src/uu/base64/src/base64.rs @@ -5,7 +5,8 @@ use clap::Command; use uu_base32::base_common; -use uucore::{encoding::Format, error::UResult, locale::get_message}; +use uucore::translate; +use uucore::{encoding::Format, error::UResult}; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { @@ -22,7 +23,7 @@ pub fn uu_app() -> Command { } fn get_info() -> (&'static str, &'static str) { - let about: &'static str = Box::leak(get_message("base64-about").into_boxed_str()); - let usage: &'static str = Box::leak(get_message("base64-usage").into_boxed_str()); + let about: &'static str = Box::leak(translate!("base64-about").into_boxed_str()); + let usage: &'static str = Box::leak(translate!("base64-usage").into_boxed_str()); (about, usage) } diff --git a/src/uu/basename/Cargo.toml b/src/uu/basename/Cargo.toml index 5123174ae2d..9fe4adc03e3 100644 --- a/src/uu/basename/Cargo.toml +++ b/src/uu/basename/Cargo.toml @@ -20,6 +20,7 @@ path = "src/basename.rs" [dependencies] clap = { workspace = true } uucore = { workspace = true } +fluent = { workspace = true } [[bin]] name = "basename" diff --git a/src/uu/basename/src/basename.rs b/src/uu/basename/src/basename.rs index b9faf5851b1..255ff611017 100644 --- a/src/uu/basename/src/basename.rs +++ b/src/uu/basename/src/basename.rs @@ -7,7 +7,6 @@ use clap::builder::ValueParser; use clap::{Arg, ArgAction, Command}; -use std::collections::HashMap; use std::ffi::OsString; use std::io::{Write, stdout}; use std::path::PathBuf; @@ -16,7 +15,7 @@ use uucore::error::{UResult, UUsageError}; use uucore::format_usage; use uucore::line_ending::LineEnding; -use uucore::locale::{get_message, get_message_with_args}; +use uucore::translate; pub mod options { pub static MULTIPLE: &str = "multiple"; @@ -41,7 +40,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if name_args.is_empty() { return Err(UUsageError::new( 1, - get_message("basename-error-missing-operand"), + translate!("basename-error-missing-operand"), )); } let multiple_paths = matches.get_one::(options::SUFFIX).is_some() @@ -60,10 +59,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { _ => { return Err(UUsageError::new( 1, - get_message_with_args( - "basename-error-extra-operand", - HashMap::from([("operand".to_string(), name_args[2].quote().to_string())]), - ), + translate!("basename-error-extra-operand", + "operand" => name_args[2].quote()), )); } } @@ -84,14 +81,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uu_app() -> Command { Command::new(uucore::util_name()) .version(uucore::crate_version!()) - .about(get_message("basename-about")) - .override_usage(format_usage(&get_message("basename-usage"))) + .about(translate!("basename-about")) + .override_usage(format_usage(&translate!("basename-usage"))) .infer_long_args(true) .arg( Arg::new(options::MULTIPLE) .short('a') .long(options::MULTIPLE) - .help(get_message("basename-help-multiple")) + .help(translate!("basename-help-multiple")) .action(ArgAction::SetTrue) .overrides_with(options::MULTIPLE), ) @@ -109,14 +106,14 @@ pub fn uu_app() -> Command { .long(options::SUFFIX) .value_name("SUFFIX") .value_parser(ValueParser::os_string()) - .help(get_message("basename-help-suffix")) + .help(translate!("basename-help-suffix")) .overrides_with(options::SUFFIX), ) .arg( Arg::new(options::ZERO) .short('z') .long(options::ZERO) - .help(get_message("basename-help-zero")) + .help(translate!("basename-help-zero")) .action(ArgAction::SetTrue) .overrides_with(options::ZERO), ) diff --git a/src/uu/basenc/Cargo.toml b/src/uu/basenc/Cargo.toml index 2f78a95751c..f68a0f11086 100644 --- a/src/uu/basenc/Cargo.toml +++ b/src/uu/basenc/Cargo.toml @@ -21,6 +21,7 @@ path = "src/basenc.rs" clap = { workspace = true } uucore = { workspace = true, features = ["encoding"] } uu_base32 = { workspace = true } +fluent = { workspace = true } [[bin]] name = "basenc" diff --git a/src/uu/basenc/src/basenc.rs b/src/uu/basenc/src/basenc.rs index d06ac3af795..c6cd48c2acd 100644 --- a/src/uu/basenc/src/basenc.rs +++ b/src/uu/basenc/src/basenc.rs @@ -8,7 +8,7 @@ use clap::{Arg, ArgAction, Command}; use uu_base32::base_common::{self, BASE_CMD_PARSE_ERROR, Config}; use uucore::error::UClapError; -use uucore::locale::get_message; +use uucore::translate; use uucore::{ encoding::Format, error::{UResult, UUsageError}, @@ -16,36 +16,36 @@ use uucore::{ fn get_encodings() -> Vec<(&'static str, Format, String)> { vec![ - ("base64", Format::Base64, get_message("basenc-help-base64")), + ("base64", Format::Base64, translate!("basenc-help-base64")), ( "base64url", Format::Base64Url, - get_message("basenc-help-base64url"), + translate!("basenc-help-base64url"), ), - ("base32", Format::Base32, get_message("basenc-help-base32")), + ("base32", Format::Base32, translate!("basenc-help-base32")), ( "base32hex", Format::Base32Hex, - get_message("basenc-help-base32hex"), + translate!("basenc-help-base32hex"), ), - ("base16", Format::Base16, get_message("basenc-help-base16")), + ("base16", Format::Base16, translate!("basenc-help-base16")), ( "base2lsbf", Format::Base2Lsbf, - get_message("basenc-help-base2lsbf"), + translate!("basenc-help-base2lsbf"), ), ( "base2msbf", Format::Base2Msbf, - get_message("basenc-help-base2msbf"), + translate!("basenc-help-base2msbf"), ), - ("z85", Format::Z85, get_message("basenc-help-z85")), + ("z85", Format::Z85, translate!("basenc-help-z85")), ] } pub fn uu_app() -> Command { - let about: &'static str = Box::leak(get_message("basenc-about").into_boxed_str()); - let usage: &'static str = Box::leak(get_message("basenc-usage").into_boxed_str()); + let about: &'static str = Box::leak(translate!("basenc-about").into_boxed_str()); + let usage: &'static str = Box::leak(translate!("basenc-usage").into_boxed_str()); let encodings = get_encodings(); let mut command = base_common::base_app(about, usage); @@ -75,7 +75,7 @@ fn parse_cmd_args(args: impl uucore::Args) -> UResult<(Config, Format)> { .ok_or_else(|| { UUsageError::new( BASE_CMD_PARSE_ERROR, - get_message("basenc-error-missing-encoding-type"), + translate!("basenc-error-missing-encoding-type"), ) })? .1; diff --git a/src/uu/cat/Cargo.toml b/src/uu/cat/Cargo.toml index 387ecbe238e..632a0d97b87 100644 --- a/src/uu/cat/Cargo.toml +++ b/src/uu/cat/Cargo.toml @@ -22,6 +22,7 @@ clap = { workspace = true } memchr = { workspace = true } thiserror = { workspace = true } uucore = { workspace = true, features = ["fast-inc", "fs", "pipes"] } +fluent = { workspace = true } [target.'cfg(unix)'.dependencies] nix = { workspace = true } diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index b1c5f9aac63..c7f975952f6 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -26,7 +26,7 @@ use uucore::display::Quotable; use uucore::error::UResult; #[cfg(not(target_os = "windows"))] use uucore::libc; -use uucore::locale::get_message; +use uucore::translate; use uucore::{fast_inc::fast_inc_one, format_usage}; /// Linux splice support @@ -284,8 +284,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uu_app() -> Command { Command::new(uucore::util_name()) .version(uucore::crate_version!()) - .override_usage(format_usage(&get_message("cat-usage"))) - .about(get_message("cat-about")) + .override_usage(format_usage(&translate!("cat-usage"))) + .about(translate!("cat-about")) .infer_long_args(true) .args_override_self(true) .arg( diff --git a/src/uu/chcon/Cargo.toml b/src/uu/chcon/Cargo.toml index ccf36056339..ab05ed53c0c 100644 --- a/src/uu/chcon/Cargo.toml +++ b/src/uu/chcon/Cargo.toml @@ -24,6 +24,7 @@ selinux = { workspace = true } thiserror = { workspace = true } libc = { workspace = true } fts-sys = { workspace = true } +fluent = { workspace = true } [[bin]] name = "chcon" diff --git a/src/uu/chcon/src/chcon.rs b/src/uu/chcon/src/chcon.rs index b2cddeab8ce..754f1c2703a 100644 --- a/src/uu/chcon/src/chcon.rs +++ b/src/uu/chcon/src/chcon.rs @@ -8,13 +8,13 @@ use clap::builder::ValueParser; use uucore::error::{UResult, USimpleError, UUsageError}; +use uucore::translate; use uucore::{display::Quotable, format_usage, show_error, show_warning}; use clap::{Arg, ArgAction, Command}; use selinux::{OpaqueSecurityContext, SecurityContext}; use std::borrow::Cow; -use std::collections::HashMap; use std::ffi::{CStr, CString, OsStr, OsString}; use std::os::raw::c_int; use std::path::{Path, PathBuf}; @@ -25,8 +25,6 @@ mod fts; use errors::*; -use uucore::locale::{get_message, get_message_with_args}; - pub mod options { pub static HELP: &str = "help"; pub static VERBOSE: &str = "verbose"; @@ -80,14 +78,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { Ok(None) => { let err = io::Error::from_raw_os_error(libc::ENODATA); Err(Error::from_io1( - get_message("chcon-op-getting-security-context"), + translate!("chcon-op-getting-security-context"), reference, err, )) } Err(r) => Err(Error::from_selinux( - get_message("chcon-op-getting-security-context"), + translate!("chcon-op-getting-security-context"), r, )), }; @@ -111,10 +109,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { Err(_r) => { return Err(USimpleError::new( libc::EXIT_FAILURE, - get_message_with_args( - "chcon-error-invalid-context", - HashMap::from([("context".to_string(), context.quote().to_string())]), - ), + translate!("chcon-error-invalid-context", "context" => context.quote()), )); } }; @@ -122,10 +117,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if SecurityContext::from_c_str(&c_context, false).check() == Some(false) { return Err(USimpleError::new( libc::EXIT_FAILURE, - get_message_with_args( - "chcon-error-invalid-context", - HashMap::from([("context".to_string(), context.quote().to_string())]), - ), + translate!("chcon-error-invalid-context", "context" => context.quote()), )); } @@ -164,42 +156,42 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uu_app() -> Command { Command::new(uucore::util_name()) .version(uucore::crate_version!()) - .about(get_message("chcon-about")) - .override_usage(format_usage(&get_message("chcon-usage"))) + .about(translate!("chcon-about")) + .override_usage(format_usage(&translate!("chcon-usage"))) .infer_long_args(true) .disable_help_flag(true) .args_override_self(true) .arg( Arg::new(options::HELP) .long(options::HELP) - .help(get_message("chcon-help-help")) + .help(translate!("chcon-help-help")) .action(ArgAction::Help), ) .arg( Arg::new(options::dereference::DEREFERENCE) .long(options::dereference::DEREFERENCE) .overrides_with(options::dereference::NO_DEREFERENCE) - .help(get_message("chcon-help-dereference")) + .help(translate!("chcon-help-dereference")) .action(ArgAction::SetTrue), ) .arg( Arg::new(options::dereference::NO_DEREFERENCE) .short('h') .long(options::dereference::NO_DEREFERENCE) - .help(get_message("chcon-help-no-dereference")) + .help(translate!("chcon-help-no-dereference")) .action(ArgAction::SetTrue), ) .arg( Arg::new(options::preserve_root::PRESERVE_ROOT) .long(options::preserve_root::PRESERVE_ROOT) .overrides_with(options::preserve_root::NO_PRESERVE_ROOT) - .help(get_message("chcon-help-preserve-root")) + .help(translate!("chcon-help-preserve-root")) .action(ArgAction::SetTrue), ) .arg( Arg::new(options::preserve_root::NO_PRESERVE_ROOT) .long(options::preserve_root::NO_PRESERVE_ROOT) - .help(get_message("chcon-help-no-preserve-root")) + .help(translate!("chcon-help-no-preserve-root")) .action(ArgAction::SetTrue), ) .arg( @@ -208,7 +200,7 @@ pub fn uu_app() -> Command { .value_name("RFILE") .value_hint(clap::ValueHint::FilePath) .conflicts_with_all([options::USER, options::ROLE, options::TYPE, options::RANGE]) - .help(get_message("chcon-help-reference")) + .help(translate!("chcon-help-reference")) .value_parser(ValueParser::os_string()), ) .arg( @@ -217,7 +209,7 @@ pub fn uu_app() -> Command { .long(options::USER) .value_name("USER") .value_hint(clap::ValueHint::Username) - .help(get_message("chcon-help-user")) + .help(translate!("chcon-help-user")) .value_parser(ValueParser::os_string()), ) .arg( @@ -225,7 +217,7 @@ pub fn uu_app() -> Command { .short('r') .long(options::ROLE) .value_name("ROLE") - .help(get_message("chcon-help-role")) + .help(translate!("chcon-help-role")) .value_parser(ValueParser::os_string()), ) .arg( @@ -233,7 +225,7 @@ pub fn uu_app() -> Command { .short('t') .long(options::TYPE) .value_name("TYPE") - .help(get_message("chcon-help-type")) + .help(translate!("chcon-help-type")) .value_parser(ValueParser::os_string()), ) .arg( @@ -241,14 +233,14 @@ pub fn uu_app() -> Command { .short('l') .long(options::RANGE) .value_name("RANGE") - .help(get_message("chcon-help-range")) + .help(translate!("chcon-help-range")) .value_parser(ValueParser::os_string()), ) .arg( Arg::new(options::RECURSIVE) .short('R') .long(options::RECURSIVE) - .help(get_message("chcon-help-recursive")) + .help(translate!("chcon-help-recursive")) .action(ArgAction::SetTrue), ) .arg( @@ -259,7 +251,7 @@ pub fn uu_app() -> Command { options::sym_links::FOLLOW_DIR_SYM_LINKS, options::sym_links::NO_FOLLOW_SYM_LINKS, ]) - .help(get_message("chcon-help-follow-arg-dir-symlink")) + .help(translate!("chcon-help-follow-arg-dir-symlink")) .action(ArgAction::SetTrue), ) .arg( @@ -270,7 +262,7 @@ pub fn uu_app() -> Command { options::sym_links::FOLLOW_ARG_DIR_SYM_LINK, options::sym_links::NO_FOLLOW_SYM_LINKS, ]) - .help(get_message("chcon-help-follow-dir-symlinks")) + .help(translate!("chcon-help-follow-dir-symlinks")) .action(ArgAction::SetTrue), ) .arg( @@ -281,14 +273,14 @@ pub fn uu_app() -> Command { options::sym_links::FOLLOW_ARG_DIR_SYM_LINK, options::sym_links::FOLLOW_DIR_SYM_LINKS, ]) - .help(get_message("chcon-help-no-follow-symlinks")) + .help(translate!("chcon-help-no-follow-symlinks")) .action(ArgAction::SetTrue), ) .arg( Arg::new(options::VERBOSE) .short('v') .long(options::VERBOSE) - .help(get_message("chcon-help-verbose")) + .help(translate!("chcon-help-verbose")) .action(ArgAction::SetTrue), ) .arg( @@ -318,24 +310,24 @@ fn parse_command_line(config: Command, args: impl uucore::Args) -> Result