Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Improve support for CLI translations using gettext #417

Merged
merged 5 commits into from
Mar 23, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions typer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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}]"
Expand Down Expand Up @@ -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)


Expand Down
Loading