Skip to content

Support or document localization of messages and flags #380

@kamalmarhubi

Description

@kamalmarhubi

Make it easy for developers to support translations of their projects.


Current steps:

  • Run cargo add clap -F string
  • If using derive API
    • Replace field names being used as value names via #[arg(value_name = ...)]
  • If using subcommands:
    • Replace Commands: header with a localized value via Command::subcommand_help_heading
    • Replace <COMMAND> value name with a localized value via Command::subcommand_value_name
  • Replace Arguments and Options: headers with localized values via Command::next_help_heading and/or Arg::help_heading
  • Disable the built-in flags (Command::disable_help_flag(false) and Command::disable_version_flag(false)) and provide your own versions (with ArgAction::Help, ArgAction::Version) with localized Arg::help
  • Replace hard coded strings in help template (e.g. Usage) with a localized version via Command::help_template
    • Requires styling Usage manually
  • Remove hard coded [] messages with Arg::hide_default_value, Arg::hide_possible_values, Arg::hide_env
  • Fork clap::error::RichFormatter, replacing any hard coded strings with localized values. Use Error::apply to swap the formatter (e.g. use Parser::try_parse to get the error, call apply, and then err.exit())
  • Replace in usages the collapsed optional named arguments placeholder [OPTIONS] by providing a custom usage with Command::override_usage

Unresolved:

Past examples:

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-helpArea: documentation, including docs.rs, readme, examples, etc...C-enhancementCategory: Raise on the bar on expectationsS-waiting-on-designStatus: Waiting on user-facing design to be resolved before implementing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions