Skip to content
Myr

mark cli messages for translation

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

authored by Saif807380 · committed by David Lord · parent c0f9c06 · Browse files · 6 files+35 added−16 removed
This commit

State

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

Diff stats

6 files+35 added−16 removed

  • tests:+1 added−0 removed
  • other:+34 added−16 removed

6 files+35 added−16 removed

modified:src/click/core.py+6 added-3 removed
4 unmodified lines
5import typing as t6from contextlib import contextmanager7from contextlib import ExitStack8from functools import update_wrapper9from gettext import gettext as _10from itertools import repeat1112from ._unicodefun import _verify_python_env13from .exceptions import Abort
981 unmodified lines
995 return e.exit_code996 except Abort:997 if not standalone_mode:998 raise998 echo("Aborted!", file=sys.stderr)999 echo(_("Aborted!"), file=sys.stderr)1000 sys.exit(1)10011002 def _main_shell_completion(self, ctx_args, prog_name, complete_var=None):1003 """Check if the shell is asking for tab completion, process
166 unmodified lines
1170 is_flag=True,1171 is_eager=True,1172 expose_value=False,1173 callback=show_help,1173 help="Show this message and exit.",1174 help=_("Show this message and exit."),1175 )11761177 def make_parser(self, ctx):1178 """Creates the underlying option parser for this command."""
101 unmodified lines
1280 """1281 if self.deprecated:1282 echo(1283 style(1283 f"DeprecationWarning: The command {self.name!r} is deprecated.",1284 _(1285 "DeprecationWarning: The command {self.name!r} is deprecated."1286 ).format(self=self),1287 fg="red",1288 ),1289 err=True,1290 )
1335 unmodified lines
modified:src/click/decorators.py+7 added-3 removed
1import inspect2import typing as t3from functools import update_wrapper4from gettext import gettext as _56from .core import Argument7from .core import Command8from .core import Group
271 unmodified lines
280 version=None,281 *param_decls,282 package_name=None,283 prog_name=None,283 message="%(prog)s, version %(version)s",284 message=None,285 **kwargs,286):287 """Add a ``--version`` option which immediately prints the version288 number and exits the program.
26 unmodified lines
315316 .. versionchanged:: 8.0317 Use :mod:`importlib.metadata` instead of ``pkg_resources``.318 """319 if message is None:320 message = _("%(prog)s, version %(version)s")321322 if version is None and package_name is None:323 frame = inspect.currentframe()324 f_globals = frame.f_back.f_globals if frame is not None else None325 # break reference cycle
58 unmodified lines
384385 kwargs.setdefault("is_flag", True)386 kwargs.setdefault("expose_value", False)387 kwargs.setdefault("is_eager", True)384 kwargs.setdefault("help", "Show the version and exit.")388 kwargs.setdefault("help", _("Show the version and exit."))389 kwargs["callback"] = callback390 return option(*param_decls, **kwargs)391392
22 unmodified lines
415416 kwargs.setdefault("is_flag", True)417 kwargs.setdefault("expose_value", False)418 kwargs.setdefault("is_eager", True)415 kwargs.setdefault("help", "Show this message and exit.")419 kwargs.setdefault("help", _("Show this message and exit."))420 kwargs["callback"] = callback421 return option(*param_decls, **kwargs)
modified:src/click/exceptions.py+14 added-4 removed
1from gettext import gettext as _23from ._compat import filename_to_ui4from ._compat import get_text_stderr5from .utils import echo6
22 unmodified lines
2930 def show(self, file=None):31 if file is None:32 file = get_text_stderr()31 echo(f"Error: {self.format_message()}", file=file)33 echo(_("Error: {self.format_message()}").format(self=self), file=file)343536class UsageError(ClickException):37 """An internal exception that signals a usage error. This typically
22 unmodified lines
60 f" {self.ctx.help_option_names[0]}' for help.\n"61 )62 if self.ctx is not None:63 color = self.ctx.color62 echo(f"{self.ctx.get_usage()}\n{hint}", file=file, color=color)63 echo(f"Error: {self.format_message()}", file=file, color=color)64 echo(65 _("{usage}\n{hint}").format(usage=self.ctx.get_usage(), hint=hint),66 file=file,67 color=color,68 )69 echo(70 _("Error: {message}").format(message=self.format_message()),71 file=file,72 color=color,73 )747576class BadParameter(UsageError):77 """An exception that formats out a standardized error message for a
75 unmodified lines
153154 def __str__(self):155 if self.message is None:156 param_name = self.param.name if self.param else None147 return f"missing parameter: {param_name}"157 return _("missing parameter: {param_name}").format(param_name=param_name)158 else:159 return self.message160161
81 unmodified lines
modified:src/click/termui.py+6 added-5 removed
2 unmodified lines
3import itertools4import os5import sys6import typing as t7from gettext import gettext as _89from ._compat import is_bytes10from ._compat import isatty11from ._compat import strip_ansi
133 unmodified lines
145 )146147 if confirmation_prompt:148 if confirmation_prompt is True:148 confirmation_prompt = "Repeat for confirmation"149 confirmation_prompt = _("Repeat for confirmation")150151 confirmation_prompt = _build_prompt(confirmation_prompt, prompt_suffix)152153 while 1:
7 unmodified lines
161 try:162 result = value_proc(value)163 except UsageError as e:164 if hide_input:164 echo("Error: the value you entered was invalid", err=err)165 echo(_("Error: the value you entered was invalid"), err=err)166 else:166 echo(f"Error: {e.message}", err=err) # noqa: B306167 echo(_("Error: {e.message}").format(e=e), err=err) # noqa: B306168 continue169 if not confirmation_prompt:170 return result171 while 1:
1 unmodified line
173 if value2:174 break175 if value == value2:176 return result176 echo("Error: the two entered values do not match", err=err)177 echo(_("Error: the two entered values do not match"), err=err)178179180def confirm(181 text, default=False, abort=False, prompt_suffix=": ", show_default=True, err=False
40 unmodified lines
222 rv = False223 elif default is not None and value == "":224 rv = default225 else:225 echo("Error: invalid input", err=err)226 echo(_("Error: invalid input"), err=err)227 continue228 break229 if abort and not rv:230 raise Abort()
531 unmodified lines
modified:tests/test_imports.py+1 added
45 unmodified lines
46 "datetime",47 "enum",48 "typing",49 "types",50 "gettext",51}5253if WIN:54 ALLOWED_IMPORTS.update(["ctypes", "ctypes.wintypes", "msvcrt", "time"])
14 unmodified lines
modified:CHANGES.rst+1 added-1 removed
195 unmodified lines
196 well as in the short help. The notice is not in all caps.197 :issue:`1791`198- When taking arguments from ``sys.argv`` on Windows, glob patterns,199 user dir, and env vars are expanded. :issue:`1096`200- Wrapped public messages with ``_(gettext)`` for i18n support. :issue:`303`201201202Version 7.1.2203-------------204205Released 2020-04-27
633 unmodified lines