-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Localisation of more strings #2902
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
base: main
Are you sure you want to change the base?
Changes from all commits
efb695e
0bbb222
be2f41c
4768c98
74d7795
aadd7e1
caf571b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,11 @@ | ||
| # Ask Ruff to accept the format method on strings, and not let pyupgrade | ||
| # always force f-strings. The latter are unfortunately not supported yet | ||
| # by Babel, a localisation library. | ||
| # | ||
| # Note: Using `# noqa: UP032` on lines has not worked, so a file | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None of these |
||
| # setting. | ||
| # ruff: noqa: UP032 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import collections.abc as cabc | ||
|
|
@@ -76,15 +84,15 @@ def _check_nested_chain( | |
| return | ||
|
|
||
| if register: | ||
| message = ( | ||
| f"It is not possible to add the group {cmd_name!r} to another" | ||
| f" group {base_command.name!r} that is in chain mode." | ||
| ) | ||
| message = _( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're only translating user-facing messages at this time, not developer-facing. Please remove all such translation markings. |
||
| "It is not possible to add the group {cmd_name!r} to another" | ||
| " group {base_cmd_name!r} that is in chain mode." | ||
| ).format(cmd_name=cmd_name, base_cmd_name=base_command.name) # noqa: UP032 | ||
| else: | ||
| message = ( | ||
| f"Found the group {cmd_name!r} as subcommand to another group " | ||
| f" {base_command.name!r} that is in chain mode. This is not supported." | ||
| ) | ||
| message = _( | ||
| "Found the group {cmd_name!r} as subcommand to another group " | ||
| " {base_cmd_name!r} that is in chain mode. This is not supported." | ||
| ).format(cmd_name=cmd_name, base_cmd_name=base_command.name) # noqa: UP032 | ||
|
|
||
| raise RuntimeError(message) | ||
|
|
||
|
|
@@ -986,8 +994,10 @@ def get_params(self, ctx: Context) -> list[Parameter]: | |
| for duplicate_opt in duplicate_opts: | ||
| warnings.warn( | ||
| ( | ||
| f"The parameter {duplicate_opt} is used more than once. " | ||
| "Remove its duplicate as parameters should be unique." | ||
| _( | ||
| "The parameter {param} is used more than once. " | ||
| "Remove its duplicate as parameters should be unique." | ||
| ).format(param=duplicate_opt) | ||
| ), | ||
| stacklevel=3, | ||
| ) | ||
|
|
@@ -1077,9 +1087,9 @@ def get_short_help_str(self, limit: int = 45) -> str: | |
|
|
||
| if self.deprecated: | ||
| deprecated_message = ( | ||
| f"(DEPRECATED: {self.deprecated})" | ||
| _("(DEPRECATED: {target})".format(target=self.deprecated)) | ||
| if isinstance(self.deprecated, str) | ||
| else "(DEPRECATED)" | ||
| else _("(DEPRECATED)") | ||
| ) | ||
| text = _("{text} {deprecated_message}").format( | ||
| text=text, deprecated_message=deprecated_message | ||
|
|
@@ -1114,9 +1124,9 @@ def format_help_text(self, ctx: Context, formatter: HelpFormatter) -> None: | |
|
|
||
| if self.deprecated: | ||
| deprecated_message = ( | ||
| f"(DEPRECATED: {self.deprecated})" | ||
| _("(DEPRECATED: {target})".format(target=self.deprecated)) | ||
| if isinstance(self.deprecated, str) | ||
| else "(DEPRECATED)" | ||
| else _("(DEPRECATED)") | ||
| ) | ||
| text = _("{text} {deprecated_message}").format( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't have ever been marked for translation. It should be removed, since you've added the translation to the proper location above. |
||
| text=text, deprecated_message=deprecated_message | ||
|
|
@@ -2123,8 +2133,10 @@ def __init__( | |
| if __debug__: | ||
| if self.type.is_composite and nargs != self.type.arity: | ||
| raise ValueError( | ||
| f"'nargs' must be {self.type.arity} (or None) for" | ||
| f" type {self.type!r}, but it was {nargs}." | ||
| _( | ||
| "'nargs' must be {arity} (or None) for" | ||
| " type {type!r}, but it was {nargs}." | ||
| ).format(arity=self.type.arity, type=self.type, nargs=nargs) | ||
| ) | ||
|
|
||
| # Skip no default or callable default. | ||
|
|
@@ -2158,14 +2170,21 @@ def __init__( | |
| if nargs > 1 and len(check_default) != nargs: | ||
| subject = "item length" if multiple else "length" | ||
| raise ValueError( | ||
| f"'default' {subject} must match nargs={nargs}." | ||
| _("'default' {subject} must match nargs={nargs}.").format( | ||
| subject=subject, nargs=nargs | ||
| ) | ||
| ) | ||
|
|
||
| if required and deprecated: | ||
| raise ValueError( | ||
| f"The {self.param_type_name} '{self.human_readable_name}' " | ||
| "is deprecated and still required. A deprecated " | ||
| f"{self.param_type_name} cannot be required." | ||
| _( | ||
| "The {type_name} '{readable_name}' " | ||
| "is deprecated and still required. A deprecated " | ||
| "{type_name} cannot be required." | ||
| ).format( | ||
| type_name=self.param_type_name, | ||
| readable_name=self.human_readable_name, | ||
| ) | ||
| ) | ||
|
|
||
| def to_info_dict(self) -> dict[str, t.Any]: | ||
|
|
@@ -2571,9 +2590,9 @@ def __init__( | |
|
|
||
| if deprecated: | ||
| deprecated_message = ( | ||
| f"(DEPRECATED: {deprecated})" | ||
| _("(DEPRECATED: {target})".format(target=deprecated)) | ||
| if isinstance(deprecated, str) | ||
| else "(DEPRECATED)" | ||
| else _("(DEPRECATED)") | ||
| ) | ||
| help = help + deprecated_message if help is not None else deprecated_message | ||
|
|
||
|
|
@@ -2676,7 +2695,7 @@ def to_info_dict(self) -> dict[str, t.Any]: | |
| def get_error_hint(self, ctx: Context) -> str: | ||
| result = super().get_error_hint(ctx) | ||
| if self.show_envvar: | ||
| result += f" (env var: '{self.envvar}')" | ||
| result += _(" (env var: '{var}')").format(var=self.envvar) # noqa: UP032 | ||
| return result | ||
|
|
||
| def _parse_decls( | ||
|
|
@@ -2690,7 +2709,7 @@ def _parse_decls( | |
| for decl in decls: | ||
| if decl.isidentifier(): | ||
| if name is not None: | ||
| raise TypeError(f"Name '{name}' defined twice") | ||
| raise TypeError(_("Name '{name}' defined twice").format(name=name)) # noqa: UP032 | ||
| name = decl | ||
| else: | ||
| split_char = ";" if decl[:1] == "/" else "/" | ||
|
|
@@ -2705,8 +2724,10 @@ def _parse_decls( | |
| secondary_opts.append(second.lstrip()) | ||
| if first == second: | ||
| raise ValueError( | ||
| f"Boolean option {decl!r} cannot use the" | ||
| " same flag for true/false." | ||
| _( | ||
| "Boolean option {decl!r} cannot use the" | ||
| " same flag for true/false." | ||
| ).format(decl=decl) | ||
| ) | ||
| else: | ||
| possible_names.append(_split_opt(decl)) | ||
|
|
@@ -2722,14 +2743,18 @@ def _parse_decls( | |
| if not expose_value: | ||
| return None, opts, secondary_opts | ||
| raise TypeError( | ||
| f"Could not determine name for option with declarations {decls!r}" | ||
| _( | ||
| "Could not determine name for option with declarations {decls!r}" | ||
| ).format(decls=decls) | ||
| ) | ||
|
|
||
| if not opts and not secondary_opts: | ||
| raise TypeError( | ||
| f"No options defined but a name was passed ({name})." | ||
| " Did you mean to declare an argument instead? Did" | ||
| f" you mean to pass '--{name}'?" | ||
| _( | ||
| "No options defined but a name was passed ({name})." | ||
| " Did you mean to declare an argument instead? Did" | ||
| " you mean to pass '--{name}'?" | ||
| ).format(name=name) | ||
| ) | ||
|
|
||
| return name, opts, secondary_opts | ||
|
|
@@ -3095,8 +3120,10 @@ def _parse_decls( | |
| name = name.replace("-", "_").lower() | ||
| else: | ||
| raise TypeError( | ||
| "Arguments take exactly one parameter declaration, got" | ||
| f" {len(decls)}: {decls}." | ||
| _( | ||
| "Arguments take exactly one parameter declaration, got" | ||
| " {length}: {decls}." | ||
| ).format(length=len(decls), decls=decls) | ||
| ) | ||
| return name, [arg], [] | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.