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
Provenance
- Commit
03e2fee- Tree
adc4bc1- Author
Saif807380 <saif1204kazi@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
c0f9c06
6 files changed+35 added−16 removed
modified:src/click/core.py+6 added-3 removed
4 unmodified lines5 import typing as t6 from contextlib import contextmanager7 from contextlib import ExitStack8 from functools import update_wrapper9+from gettext import gettext as _10 from itertools import repeat11 12 from ._unicodefun import _verify_python_env13 from .exceptions import Abort981 unmodified lines995 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)1001 1002 def _main_shell_completion(self, ctx_args, prog_name, complete_var=None):1003 """Check if the shell is asking for tab completion, process166 unmodified lines1170 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 )1176 1177 def make_parser(self, ctx):1178 """Creates the underlying option parser for this command."""101 unmodified lines1280 """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 linesmodified:src/click/decorators.py+7 added-3 removed
1 import inspect2 import typing as t3 from functools import update_wrapper4+from gettext import gettext as _5 6 from .core import Argument7 from .core import Command8 from .core import Group271 unmodified lines280 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 lines315 316 .. versionchanged:: 8.0317 Use :mod:`importlib.metadata` instead of ``pkg_resources``.318 """319+ if message is None:320+ message = _("%(prog)s, version %(version)s")321+322 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 cycle58 unmodified lines384 385 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)391 392 22 unmodified lines415 416 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
1+from gettext import gettext as _2+3 from ._compat import filename_to_ui4 from ._compat import get_text_stderr5 from .utils import echo6 22 unmodified lines29 30 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)34 35 36 class UsageError(ClickException):37 """An internal exception that signals a usage error. This typically22 unmodified lines60 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+ )74 75 76 class BadParameter(UsageError):77 """An exception that formats out a standardized error message for a75 unmodified lines153 154 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.message160 161 81 unmodified linesmodified:src/click/termui.py+6 added-5 removed
2 unmodified lines3 import itertools4 import os5 import sys6 import typing as t7+from gettext import gettext as _8 9 from ._compat import is_bytes10 from ._compat import isatty11 from ._compat import strip_ansi133 unmodified lines145 )146 147 if confirmation_prompt:148 if confirmation_prompt is True:148- confirmation_prompt = "Repeat for confirmation"149+ confirmation_prompt = _("Repeat for confirmation")150 151 confirmation_prompt = _build_prompt(confirmation_prompt, prompt_suffix)152 153 while 1:7 unmodified lines161 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 line173 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)178 179 180 def confirm(181 text, default=False, abort=False, prompt_suffix=": ", show_default=True, err=False40 unmodified lines222 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 linesmodified:tests/test_imports.py+1 added
45 unmodified lines46 "datetime",47 "enum",48 "typing",49 "types",50+ "gettext",51 }52 53 if WIN:54 ALLOWED_IMPORTS.update(["ctypes", "ctypes.wintypes", "msvcrt", "time"])14 unmodified linesmodified:CHANGES.rst+1 added-1 removed
195 unmodified lines196 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`201 201-202 Version 7.1.2203 -------------204 205 Released 2020-04-27633 unmodified lines