mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
Merge pull request #8054 from sylvestre/locale3
l10n: convert the md files to fluent
This commit is contained in:
Generated
+1
@@ -3601,6 +3601,7 @@ dependencies = [
|
||||
"dunce",
|
||||
"fluent",
|
||||
"fluent-bundle",
|
||||
"fluent-syntax",
|
||||
"glob",
|
||||
"hex",
|
||||
"itertools 0.14.0",
|
||||
|
||||
@@ -364,6 +364,7 @@ digest = "0.10.7"
|
||||
fluent-bundle = "0.16.0"
|
||||
fluent = "0.17.0"
|
||||
unic-langid = "0.9.6"
|
||||
fluent-syntax = "0.12.0"
|
||||
|
||||
uucore = { version = "0.1.0", package = "uucore", path = "src/uucore" }
|
||||
uucore_procs = { version = "0.1.0", package = "uucore_procs", path = "src/uucore_procs" }
|
||||
|
||||
Generated
+1
@@ -1418,6 +1418,7 @@ dependencies = [
|
||||
"dunce",
|
||||
"fluent",
|
||||
"fluent-bundle",
|
||||
"fluent-syntax",
|
||||
"glob",
|
||||
"hex",
|
||||
"itertools",
|
||||
|
||||
+121
-7
@@ -3,7 +3,7 @@
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
|
||||
// spell-checker:ignore manpages mangen
|
||||
// spell-checker:ignore manpages mangen prefixcat testcat
|
||||
|
||||
use clap::{Arg, Command};
|
||||
use clap_complete::Shell;
|
||||
@@ -14,6 +14,7 @@ use std::io::{self, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::locale;
|
||||
|
||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
@@ -50,6 +51,48 @@ fn name(binary_path: &Path) -> Option<&str> {
|
||||
binary_path.file_stem()?.to_str()
|
||||
}
|
||||
|
||||
fn get_canonical_util_name(util_name: &str) -> &str {
|
||||
match util_name {
|
||||
// uu_test aliases - '[' is an alias for test
|
||||
"[" => "test",
|
||||
|
||||
// hashsum aliases - all these hash commands are aliases for hashsum
|
||||
"md5sum" | "sha1sum" | "sha224sum" | "sha256sum" | "sha384sum" | "sha512sum"
|
||||
| "sha3sum" | "sha3-224sum" | "sha3-256sum" | "sha3-384sum" | "sha3-512sum"
|
||||
| "shake128sum" | "shake256sum" | "b2sum" | "b3sum" => "hashsum",
|
||||
|
||||
"dir" => "ls", // dir is an alias for ls
|
||||
|
||||
// Default case - return the util name as is
|
||||
_ => util_name,
|
||||
}
|
||||
}
|
||||
|
||||
fn find_prefixed_util<'a>(
|
||||
binary_name: &str,
|
||||
mut util_keys: impl Iterator<Item = &'a str>,
|
||||
) -> Option<&'a str> {
|
||||
util_keys.find(|util| {
|
||||
binary_name.ends_with(*util)
|
||||
&& binary_name.len() > util.len() // Ensure there's actually a prefix
|
||||
&& !binary_name[..binary_name.len() - (*util).len()]
|
||||
.ends_with(char::is_alphanumeric)
|
||||
})
|
||||
}
|
||||
|
||||
fn setup_localization_or_exit(util_name: &str) {
|
||||
locale::setup_localization(get_canonical_util_name(util_name)).unwrap_or_else(|err| {
|
||||
match err {
|
||||
uucore::locale::LocalizationError::ParseResource {
|
||||
error: err_msg,
|
||||
snippet,
|
||||
} => eprintln!("Localization parse error at {snippet}: {err_msg}"),
|
||||
other => eprintln!("Could not init the localization system: {other}"),
|
||||
}
|
||||
process::exit(99)
|
||||
});
|
||||
}
|
||||
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
fn main() {
|
||||
uucore::panic::mute_sigpipe_panic();
|
||||
@@ -70,13 +113,10 @@ fn main() {
|
||||
|
||||
// binary name equals prefixed util name?
|
||||
// * prefix/stem may be any string ending in a non-alphanumeric character
|
||||
let util_name = if let Some(util) = utils.keys().find(|util| {
|
||||
binary_as_util.ends_with(*util)
|
||||
&& !binary_as_util[..binary_as_util.len() - (*util).len()]
|
||||
.ends_with(char::is_alphanumeric)
|
||||
}) {
|
||||
// For example, if the binary is named `uu_test`, it will match `test` as a utility.
|
||||
let util_name = if let Some(util) = find_prefixed_util(binary_as_util, utils.keys().copied()) {
|
||||
// prefixed util => replace 0th (aka, executable name) argument
|
||||
Some(OsString::from(*util))
|
||||
Some(OsString::from(util))
|
||||
} else {
|
||||
// unmatched binary name => regard as multi-binary container and advance argument list
|
||||
uucore::set_utility_is_second_arg();
|
||||
@@ -111,6 +151,12 @@ fn main() {
|
||||
|
||||
match utils.get(util) {
|
||||
Some(&(uumain, _)) => {
|
||||
// TODO: plug the deactivation of the translation
|
||||
// and load the English strings directly at compilation time in the
|
||||
// binary to avoid the load of the flt
|
||||
// Could be something like:
|
||||
// #[cfg(not(feature = "only_english"))]
|
||||
setup_localization_or_exit(util);
|
||||
process::exit(uumain(vec![util_os].into_iter().chain(args)));
|
||||
}
|
||||
None => {
|
||||
@@ -213,6 +259,7 @@ fn gen_manpage<T: uucore::Args>(
|
||||
let command = if utility == "coreutils" {
|
||||
gen_coreutils_app(util_map)
|
||||
} else {
|
||||
setup_localization_or_exit(utility);
|
||||
util_map.get(utility).unwrap().1()
|
||||
};
|
||||
|
||||
@@ -239,3 +286,70 @@ fn gen_coreutils_app<T: uucore::Args>(util_map: &UtilityMap<T>) -> Command {
|
||||
}
|
||||
command
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::path::Path;
|
||||
|
||||
#[test]
|
||||
fn test_get_canonical_util_name() {
|
||||
// Test a few key aliases
|
||||
assert_eq!(get_canonical_util_name("["), "test");
|
||||
assert_eq!(get_canonical_util_name("md5sum"), "hashsum");
|
||||
assert_eq!(get_canonical_util_name("dir"), "ls");
|
||||
|
||||
// Test passthrough case
|
||||
assert_eq!(get_canonical_util_name("cat"), "cat");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_name() {
|
||||
// Test normal executable name
|
||||
assert_eq!(name(Path::new("/usr/bin/ls")), Some("ls"));
|
||||
assert_eq!(name(Path::new("cat")), Some("cat"));
|
||||
assert_eq!(
|
||||
name(Path::new("./target/debug/coreutils")),
|
||||
Some("coreutils")
|
||||
);
|
||||
|
||||
// Test with extensions
|
||||
assert_eq!(name(Path::new("program.exe")), Some("program"));
|
||||
assert_eq!(name(Path::new("/path/to/utility.bin")), Some("utility"));
|
||||
|
||||
// Test edge cases
|
||||
assert_eq!(name(Path::new("")), None);
|
||||
assert_eq!(name(Path::new("/")), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_prefixed_util() {
|
||||
let utils = ["test", "cat", "ls", "cp"];
|
||||
|
||||
// Test exact prefixed matches
|
||||
assert_eq!(
|
||||
find_prefixed_util("uu_test", utils.iter().copied()),
|
||||
Some("test")
|
||||
);
|
||||
assert_eq!(
|
||||
find_prefixed_util("my-cat", utils.iter().copied()),
|
||||
Some("cat")
|
||||
);
|
||||
assert_eq!(
|
||||
find_prefixed_util("prefix_ls", utils.iter().copied()),
|
||||
Some("ls")
|
||||
);
|
||||
|
||||
// Test non-alphanumeric separator requirement
|
||||
assert_eq!(find_prefixed_util("prefixcat", utils.iter().copied()), None); // no separator
|
||||
assert_eq!(find_prefixed_util("testcat", utils.iter().copied()), None); // no separator
|
||||
|
||||
// Test no match
|
||||
assert_eq!(find_prefixed_util("unknown", utils.iter().copied()), None);
|
||||
assert_eq!(find_prefixed_util("", utils.iter().copied()), None);
|
||||
|
||||
// Test exact util name (should not match as prefixed)
|
||||
assert_eq!(find_prefixed_util("test", utils.iter().copied()), None);
|
||||
assert_eq!(find_prefixed_util("cat", utils.iter().copied()), None);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,10 @@ use platform_info::*;
|
||||
|
||||
use clap::Command;
|
||||
use uucore::error::{UResult, USimpleError};
|
||||
use uucore::locale::{self, get_message};
|
||||
use uucore::locale::get_message;
|
||||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
locale::setup_localization(uucore::util_name())?;
|
||||
uu_app().try_get_matches_from(args)?;
|
||||
|
||||
let uts =
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
# base32
|
||||
|
||||
```
|
||||
base32 [OPTION]... [FILE]
|
||||
```
|
||||
|
||||
encode/decode data and print to standard output
|
||||
With no FILE, or when FILE is -, read standard input.
|
||||
|
||||
The data are encoded as described for the base32 alphabet in RFC 4648.
|
||||
When decoding, the input may contain newlines in addition
|
||||
to the bytes of the formal base32 alphabet. Use --ignore-garbage
|
||||
to attempt to recover from any other non-alphabet bytes in the
|
||||
encoded stream.
|
||||
@@ -0,0 +1,9 @@
|
||||
base32-about = encode/decode data and print to standard output
|
||||
With no FILE, or when FILE is -, read standard input.
|
||||
|
||||
The data are encoded as described for the base32 alphabet in RFC 4648.
|
||||
When decoding, the input may contain newlines in addition
|
||||
to the bytes of the formal base32 alphabet. Use --ignore-garbage
|
||||
to attempt to recover from any other non-alphabet bytes in the
|
||||
encoded stream.
|
||||
base32-usage = base32 [OPTION]... [FILE]
|
||||
+12
-11
@@ -5,24 +5,25 @@
|
||||
|
||||
pub mod base_common;
|
||||
|
||||
use base_common::ReadSeek;
|
||||
use clap::Command;
|
||||
use uucore::{encoding::Format, error::UResult, help_about, help_usage};
|
||||
|
||||
const ABOUT: &str = help_about!("base32.md");
|
||||
const USAGE: &str = help_usage!("base32.md");
|
||||
use uucore::{encoding::Format, error::UResult, locale::get_message};
|
||||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let format = Format::Base32;
|
||||
|
||||
let config = base_common::parse_base_cmd_args(args, ABOUT, USAGE)?;
|
||||
|
||||
let mut input: Box<dyn ReadSeek> = base_common::get_input(&config)?;
|
||||
|
||||
let (about, usage) = get_info();
|
||||
let config = base_common::parse_base_cmd_args(args, about, usage)?;
|
||||
let mut input = base_common::get_input(&config)?;
|
||||
base_common::handle_input(&mut input, format, config)
|
||||
}
|
||||
|
||||
pub fn uu_app() -> Command {
|
||||
base_common::base_app(ABOUT, USAGE)
|
||||
let (about, usage) = get_info();
|
||||
base_common::base_app(about, usage)
|
||||
}
|
||||
|
||||
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());
|
||||
(about, usage)
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
# base64
|
||||
|
||||
```
|
||||
base64 [OPTION]... [FILE]
|
||||
```
|
||||
|
||||
encode/decode data and print to standard output
|
||||
With no FILE, or when FILE is -, read standard input.
|
||||
|
||||
The data are encoded as described for the base64 alphabet in RFC 3548.
|
||||
When decoding, the input may contain newlines in addition
|
||||
to the bytes of the formal base64 alphabet. Use --ignore-garbage
|
||||
to attempt to recover from any other non-alphabet bytes in the
|
||||
encoded stream.
|
||||
@@ -0,0 +1,9 @@
|
||||
base64-about = encode/decode data and print to standard output
|
||||
With no FILE, or when FILE is -, read standard input.
|
||||
|
||||
The data are encoded as described for the base64 alphabet in RFC 3548.
|
||||
When decoding, the input may contain newlines in addition
|
||||
to the bytes of the formal base64 alphabet. Use --ignore-garbage
|
||||
to attempt to recover from any other non-alphabet bytes in the
|
||||
encoded stream.
|
||||
base64-usage = base64 [OPTION]... [FILE]
|
||||
@@ -5,22 +5,24 @@
|
||||
|
||||
use clap::Command;
|
||||
use uu_base32::base_common;
|
||||
use uucore::{encoding::Format, error::UResult, help_about, help_usage};
|
||||
|
||||
const ABOUT: &str = help_about!("base64.md");
|
||||
const USAGE: &str = help_usage!("base64.md");
|
||||
use uucore::{encoding::Format, error::UResult, locale::get_message};
|
||||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let format = Format::Base64;
|
||||
|
||||
let config = base_common::parse_base_cmd_args(args, ABOUT, USAGE)?;
|
||||
|
||||
let (about, usage) = get_info();
|
||||
let config = base_common::parse_base_cmd_args(args, about, usage)?;
|
||||
let mut input = base_common::get_input(&config)?;
|
||||
|
||||
base_common::handle_input(&mut input, format, config)
|
||||
}
|
||||
|
||||
pub fn uu_app() -> Command {
|
||||
base_common::base_app(ABOUT, USAGE)
|
||||
let (about, usage) = get_info();
|
||||
base_common::base_app(about, usage)
|
||||
}
|
||||
|
||||
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());
|
||||
(about, usage)
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
# basename
|
||||
|
||||
```
|
||||
basename [-z] NAME [SUFFIX]
|
||||
basename OPTION... NAME...
|
||||
```
|
||||
|
||||
Print NAME with any leading directory components removed
|
||||
If specified, also remove a trailing SUFFIX
|
||||
@@ -0,0 +1,4 @@
|
||||
basename-about = Print NAME with any leading directory components removed
|
||||
If specified, also remove a trailing SUFFIX
|
||||
basename-usage = basename [-z] NAME [SUFFIX]
|
||||
basename OPTION... NAME...
|
||||
@@ -9,12 +9,10 @@ use clap::{Arg, ArgAction, Command};
|
||||
use std::path::{PathBuf, is_separator};
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{UResult, UUsageError};
|
||||
use uucore::format_usage;
|
||||
use uucore::line_ending::LineEnding;
|
||||
use uucore::{format_usage, help_about, help_usage};
|
||||
|
||||
static ABOUT: &str = help_about!("basename.md");
|
||||
|
||||
const USAGE: &str = help_usage!("basename.md");
|
||||
use uucore::locale::get_message;
|
||||
|
||||
pub mod options {
|
||||
pub static MULTIPLE: &str = "multiple";
|
||||
@@ -77,8 +75,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
pub fn uu_app() -> Command {
|
||||
Command::new(uucore::util_name())
|
||||
.version(uucore::crate_version!())
|
||||
.about(ABOUT)
|
||||
.override_usage(format_usage(USAGE))
|
||||
.about(get_message("basename-about"))
|
||||
.override_usage(format_usage(&get_message("basename-usage")))
|
||||
.infer_long_args(true)
|
||||
.arg(
|
||||
Arg::new(options::MULTIPLE)
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
# basenc
|
||||
|
||||
```
|
||||
basenc [OPTION]... [FILE]
|
||||
```
|
||||
|
||||
Encode/decode data and print to standard output
|
||||
With no FILE, or when FILE is -, read standard input.
|
||||
|
||||
When decoding, the input may contain newlines in addition to the bytes of
|
||||
the formal alphabet. Use --ignore-garbage to attempt to recover
|
||||
from any other non-alphabet bytes in the encoded stream.
|
||||
@@ -0,0 +1,7 @@
|
||||
basenc-about = Encode/decode data and print to standard output
|
||||
With no FILE, or when FILE is -, read standard input.
|
||||
|
||||
When decoding, the input may contain newlines in addition to the bytes of
|
||||
the formal alphabet. Use --ignore-garbage to attempt to recover
|
||||
from any other non-alphabet bytes in the encoded stream.
|
||||
basenc-usage = basenc [OPTION]... [FILE]
|
||||
@@ -8,15 +8,11 @@
|
||||
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::{
|
||||
encoding::Format,
|
||||
error::{UResult, UUsageError},
|
||||
};
|
||||
use uucore::{help_about, help_usage};
|
||||
|
||||
const ABOUT: &str = help_about!("basenc.md");
|
||||
const USAGE: &str = help_usage!("basenc.md");
|
||||
|
||||
const ENCODINGS: &[(&str, Format, &str)] = &[
|
||||
("base64", Format::Base64, "same as 'base64' program"),
|
||||
("base64url", Format::Base64Url, "file- and url-safe base64"),
|
||||
@@ -47,7 +43,10 @@ const ENCODINGS: &[(&str, Format, &str)] = &[
|
||||
];
|
||||
|
||||
pub fn uu_app() -> Command {
|
||||
let mut command = base_common::base_app(ABOUT, USAGE);
|
||||
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 mut command = base_common::base_app(about, usage);
|
||||
for encoding in ENCODINGS {
|
||||
let raw_arg = Arg::new(encoding.0)
|
||||
.long(encoding.0)
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
# cat
|
||||
|
||||
```
|
||||
cat [OPTION]... [FILE]...
|
||||
```
|
||||
|
||||
Concatenate FILE(s), or standard input, to standard output
|
||||
With no FILE, or when FILE is -, read standard input.
|
||||
@@ -0,0 +1,3 @@
|
||||
cat-about = Concatenate FILE(s), or standard input, to standard output
|
||||
With no FILE, or when FILE is -, read standard input.
|
||||
cat-usage = cat [OPTION]... [FILE]...
|
||||
@@ -24,15 +24,13 @@ use thiserror::Error;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::UResult;
|
||||
use uucore::fs::FileInformation;
|
||||
use uucore::{fast_inc::fast_inc_one, format_usage, help_about, help_usage};
|
||||
use uucore::locale::get_message;
|
||||
use uucore::{fast_inc::fast_inc_one, format_usage};
|
||||
|
||||
/// Linux splice support
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
mod splice;
|
||||
|
||||
const USAGE: &str = help_usage!("cat.md");
|
||||
const ABOUT: &str = help_about!("cat.md");
|
||||
|
||||
// Allocate 32 digits for the line number.
|
||||
// An estimate is that we can print about 1e8 lines/seconds, so 32 digits
|
||||
// would be enough for billions of universe lifetimes.
|
||||
@@ -275,8 +273,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(USAGE))
|
||||
.about(ABOUT)
|
||||
.override_usage(format_usage(&get_message("cat-usage")))
|
||||
.about(get_message("cat-about"))
|
||||
.infer_long_args(true)
|
||||
.args_override_self(true)
|
||||
.arg(
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user