Skip to content
Myr

✨ Improve support for CLI translations uisng gettext (#417)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by mjod · committed by GitHub · parent 5728b2a · Browse files · 2 files+14 added−17 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Marcin Jodłowiec <superyode@gmail.com>
  • Co-authored-by: svlandeg <svlandeg@github.com>

Diff stats

2 files+14 added−17 removed

  • other:+14 added−17 removed

2 files+14 added−17 removed

modified:typer/core.py+4 added-8 removed
168 unmodified lines
169 if _get_click_major() > 7:170 default_value = obj.get_default(ctx, call=False)171 else:172 if inspect.isfunction(obj.default):173 default_value = "(dynamic)"173 default_value = _("(dynamic)")174 else:175 default_value = obj.default176 finally:177 ctx.resilient_parsing = resilient
217 unmodified lines
395 # Typer override end396 if default_string:397 extra.append(_("default: {default}").format(default=default_string))398 if self.required:399 extra.append("required")399 extra.append(_("required"))400 if extra:401 extra_str = ";".join(extra)402 help = f"{help} [{extra_str}]" if help else f"[{extra_str}]"403 return name, help
223 unmodified lines
627 args.append(rv)628 elif param.param_type_name == "option":629 opts.append(rv)630631 # TODO: explore adding Click's gettext support, e.g.:632 # from gettext import gettext as _633 # with formatter.section(_("Options")):634 # ...631 if args:636 with formatter.section("Arguments"):632 with formatter.section(_("Arguments")):633 formatter.write_dl(args)634 if opts:639 with formatter.section("Options"):635 with formatter.section(_("Options")):636 formatter.write_dl(opts)637638639def _typer_main_shell_completion(
161 unmodified lines
modified:typer/rich_utils.py+10 added-9 removed
1 unmodified line
23import inspect4import sys5from collections import defaultdict6from gettext import gettext as _7from os import getenv8from typing import Any, DefaultDict, Dict, Iterable, List, Optional, Union910import click
69 unmodified lines
80if _TYPER_FORCE_DISABLE_TERMINAL:81 FORCE_TERMINAL = False8283# Fixed strings83DEPRECATED_STRING = "(deprecated) "84DEFAULT_STRING = "[default: {}]"85ENVVAR_STRING = "[env var: {}]"84DEPRECATED_STRING = _("(deprecated) ")85DEFAULT_STRING = _("[default: {}]")86ENVVAR_STRING = _("[env var: {}]")87REQUIRED_SHORT_STRING = "*"87REQUIRED_LONG_STRING = "[required]"88REQUIRED_LONG_STRING = _("[required]")89RANGE_STRING = " [{}]"89ARGUMENTS_PANEL_TITLE = "Arguments"90OPTIONS_PANEL_TITLE = "Options"91COMMANDS_PANEL_TITLE = "Commands"92ERRORS_PANEL_TITLE = "Error"93ABORTED_TEXT = "Aborted."90ARGUMENTS_PANEL_TITLE = _("Arguments")91OPTIONS_PANEL_TITLE = _("Options")92COMMANDS_PANEL_TITLE = _("Commands")93ERRORS_PANEL_TITLE = _("Error")94ABORTED_TEXT = _("Aborted.")9596MARKUP_MODE_MARKDOWN = "markdown"97MARKUP_MODE_RICH = "rich"98_RICH_HELP_PANEL_NAME = "rich_help_panel"
595 unmodified lines