summaryrefslogtreecommitdiff
path: root/src/click
diff options
context:
space:
mode:
authorSaif807380 <saif1204kazi@gmail.com>2021-04-01 17:11:37 +0530
committerDavid Lord <davidism@gmail.com>2021-04-03 09:54:11 -0700
commit03e2fee8a99f08976aef0d38cb3fa372a94c928a (patch)
treeadc4bc1df92d0fd2a2f58bf0126e429c2a1c5ddf /src/click
parentc0f9c06aa123e75466829bd41985a44a70b6c625 (diff)
downloadclick-03e2fee8a99f08976aef0d38cb3fa372a94c928a.tar.gz
mark cli messages for translation
Diffstat (limited to 'src/click')
-rw-r--r--src/click/core.py9
-rw-r--r--src/click/decorators.py10
-rw-r--r--src/click/exceptions.py18
-rw-r--r--src/click/termui.py11
4 files changed, 33 insertions, 15 deletions
diff --git a/src/click/core.py b/src/click/core.py
index 80b1075..1b91af9 100644
--- a/src/click/core.py
+++ b/src/click/core.py
@@ -6,6 +6,7 @@ import typing as t
from contextlib import contextmanager
from contextlib import ExitStack
from functools import update_wrapper
+from gettext import gettext as _
from itertools import repeat
from ._unicodefun import _verify_python_env
@@ -995,7 +996,7 @@ class BaseCommand:
except Abort:
if not standalone_mode:
raise
- echo("Aborted!", file=sys.stderr)
+ echo(_("Aborted!"), file=sys.stderr)
sys.exit(1)
def _main_shell_completion(self, ctx_args, prog_name, complete_var=None):
@@ -1170,7 +1171,7 @@ class Command(BaseCommand):
is_eager=True,
expose_value=False,
callback=show_help,
- help="Show this message and exit.",
+ help=_("Show this message and exit."),
)
def make_parser(self, ctx):
@@ -1280,7 +1281,9 @@ class Command(BaseCommand):
if self.deprecated:
echo(
style(
- f"DeprecationWarning: The command {self.name!r} is deprecated.",
+ _(
+ "DeprecationWarning: The command {self.name!r} is deprecated."
+ ).format(self=self),
fg="red",
),
err=True,
diff --git a/src/click/decorators.py b/src/click/decorators.py
index 43c8fa2..13fb156 100644
--- a/src/click/decorators.py
+++ b/src/click/decorators.py
@@ -1,6 +1,7 @@
import inspect
import typing as t
from functools import update_wrapper
+from gettext import gettext as _
from .core import Argument
from .core import Command
@@ -280,7 +281,7 @@ def version_option(
*param_decls,
package_name=None,
prog_name=None,
- message="%(prog)s, version %(version)s",
+ message=None,
**kwargs,
):
"""Add a ``--version`` option which immediately prints the version
@@ -315,6 +316,9 @@ def version_option(
.. versionchanged:: 8.0
Use :mod:`importlib.metadata` instead of ``pkg_resources``.
"""
+ if message is None:
+ message = _("%(prog)s, version %(version)s")
+
if version is None and package_name is None:
frame = inspect.currentframe()
f_globals = frame.f_back.f_globals if frame is not None else None
@@ -381,7 +385,7 @@ def version_option(
kwargs.setdefault("is_flag", True)
kwargs.setdefault("expose_value", False)
kwargs.setdefault("is_eager", True)
- kwargs.setdefault("help", "Show the version and exit.")
+ kwargs.setdefault("help", _("Show the version and exit."))
kwargs["callback"] = callback
return option(*param_decls, **kwargs)
@@ -412,6 +416,6 @@ def help_option(*param_decls, **kwargs):
kwargs.setdefault("is_flag", True)
kwargs.setdefault("expose_value", False)
kwargs.setdefault("is_eager", True)
- kwargs.setdefault("help", "Show this message and exit.")
+ kwargs.setdefault("help", _("Show this message and exit."))
kwargs["callback"] = callback
return option(*param_decls, **kwargs)
diff --git a/src/click/exceptions.py b/src/click/exceptions.py
index 9623cd8..81a1469 100644
--- a/src/click/exceptions.py
+++ b/src/click/exceptions.py
@@ -1,3 +1,5 @@
+from gettext import gettext as _
+
from ._compat import filename_to_ui
from ._compat import get_text_stderr
from .utils import echo
@@ -28,7 +30,7 @@ class ClickException(Exception):
def show(self, file=None):
if file is None:
file = get_text_stderr()
- echo(f"Error: {self.format_message()}", file=file)
+ echo(_("Error: {self.format_message()}").format(self=self), file=file)
class UsageError(ClickException):
@@ -59,8 +61,16 @@ class UsageError(ClickException):
)
if self.ctx is not None:
color = self.ctx.color
- echo(f"{self.ctx.get_usage()}\n{hint}", file=file, color=color)
- echo(f"Error: {self.format_message()}", file=file, color=color)
+ echo(
+ _("{usage}\n{hint}").format(usage=self.ctx.get_usage(), hint=hint),
+ file=file,
+ color=color,
+ )
+ echo(
+ _("Error: {message}").format(message=self.format_message()),
+ file=file,
+ color=color,
+ )
class BadParameter(UsageError):
@@ -144,7 +154,7 @@ class MissingParameter(BadParameter):
def __str__(self):
if self.message is None:
param_name = self.param.name if self.param else None
- return f"missing parameter: {param_name}"
+ return _("missing parameter: {param_name}").format(param_name=param_name)
else:
return self.message
diff --git a/src/click/termui.py b/src/click/termui.py
index 8342fde..72b03f8 100644
--- a/src/click/termui.py
+++ b/src/click/termui.py
@@ -4,6 +4,7 @@ import itertools
import os
import sys
import typing as t
+from gettext import gettext as _
from ._compat import is_bytes
from ._compat import isatty
@@ -145,7 +146,7 @@ def prompt(
if confirmation_prompt:
if confirmation_prompt is True:
- confirmation_prompt = "Repeat for confirmation"
+ confirmation_prompt = _("Repeat for confirmation")
confirmation_prompt = _build_prompt(confirmation_prompt, prompt_suffix)
@@ -161,9 +162,9 @@ def prompt(
result = value_proc(value)
except UsageError as e:
if hide_input:
- echo("Error: the value you entered was invalid", err=err)
+ echo(_("Error: the value you entered was invalid"), err=err)
else:
- echo(f"Error: {e.message}", err=err) # noqa: B306
+ echo(_("Error: {e.message}").format(e=e), err=err) # noqa: B306
continue
if not confirmation_prompt:
return result
@@ -173,7 +174,7 @@ def prompt(
break
if value == value2:
return result
- echo("Error: the two entered values do not match", err=err)
+ echo(_("Error: the two entered values do not match"), err=err)
def confirm(
@@ -222,7 +223,7 @@ def confirm(
elif default is not None and value == "":
rv = default
else:
- echo("Error: invalid input", err=err)
+ echo(_("Error: invalid input"), err=err)
continue
break
if abort and not rv: