Localization is most reliable when the command metadata is translated before
parsing and any resulting error goes through the same localizer.
LocalizedParse provides that path for the common case:
use clap::Parser;
use ortho_config::{LocalizedParse, NoOpLocalizer};
#[derive(Debug, Parser)]
#[command(name = "acme", bin_name = "acme")]
struct Cli {
#[arg(long)]
verbose: bool,
}
fn main() -> Result<(), clap::Error> {
let localizer = NoOpLocalizer::new();
let cli = Cli::try_parse_localized_from(
["acme", "--verbose"],
&localizer,
)?;
assert!(cli.verbose);
println!("verbose={}", cli.verbose);
Ok(())
}
Use FluentLocalizer for translated catalogues. Use LocalizeCmd::with_base
with parse_localized_command when catalogue identifiers must use an explicit
root rather than the binary name. Missing translations fall back to the original
clap text and emit a warning event, so users still receive a useful error.