diff --git a/typer/core.py b/typer/core.py index 0c73784c23..37e7b2f78f 100644 --- a/typer/core.py +++ b/typer/core.py @@ -162,7 +162,7 @@ def _extract_default_help_str( default_value = obj.get_default(ctx, call=False) else: if inspect.isfunction(obj.default): - default_value = "(dynamic)" + default_value = _("(dynamic)") else: default_value = obj.default finally: @@ -388,7 +388,7 @@ def get_help_record(self, ctx: click.Context) -> Optional[Tuple[str, str]]: if default_string: extra.append(_("default: {default}").format(default=default_string)) if self.required: - extra.append("required") + extra.append(_("required")) if extra: extra_str = ";".join(extra) help = f"{help} [{extra_str}]" if help else f"[{extra_str}]" @@ -620,15 +620,11 @@ def _typer_format_options( elif param.param_type_name == "option": opts.append(rv) - # TODO: explore adding Click's gettext support, e.g.: - # from gettext import gettext as _ - # with formatter.section(_("Options")): - # ... if args: - with formatter.section("Arguments"): + with formatter.section(_("Arguments")): formatter.write_dl(args) if opts: - with formatter.section("Options"): + with formatter.section(_("Options")): formatter.write_dl(opts) diff --git a/typer/rich_utils.py b/typer/rich_utils.py index fdb61b6719..51da5ca6ea 100644 --- a/typer/rich_utils.py +++ b/typer/rich_utils.py @@ -3,6 +3,7 @@ import inspect import sys from collections import defaultdict +from gettext import gettext as _ from os import getenv from typing import Any, DefaultDict, Dict, Iterable, List, Optional, Union @@ -80,17 +81,17 @@ FORCE_TERMINAL = False # Fixed strings -DEPRECATED_STRING = "(deprecated) " -DEFAULT_STRING = "[default: {}]" -ENVVAR_STRING = "[env var: {}]" +DEPRECATED_STRING = _("(deprecated) ") +DEFAULT_STRING = _("[default: {}]") +ENVVAR_STRING = _("[env var: {}]") REQUIRED_SHORT_STRING = "*" -REQUIRED_LONG_STRING = "[required]" +REQUIRED_LONG_STRING = _("[required]") RANGE_STRING = " [{}]" -ARGUMENTS_PANEL_TITLE = "Arguments" -OPTIONS_PANEL_TITLE = "Options" -COMMANDS_PANEL_TITLE = "Commands" -ERRORS_PANEL_TITLE = "Error" -ABORTED_TEXT = "Aborted." +ARGUMENTS_PANEL_TITLE = _("Arguments") +OPTIONS_PANEL_TITLE = _("Options") +COMMANDS_PANEL_TITLE = _("Commands") +ERRORS_PANEL_TITLE = _("Error") +ABORTED_TEXT = _("Aborted.") MARKUP_MODE_MARKDOWN = "markdown" MARKUP_MODE_RICH = "rich"