Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem and proposal
Using Click in a multi-lingual package, we would like to localise more strings than currently possible.
In our work before this PR, we reach like:
The package we develop yields the
artefacts
command, based on Click, works alright to translate our strings, as well as a range of strings in Click wrapped withgettext
.With this PR, we get:
Which looks like possibly full coverage of meaningful strings in Click.
Note this PR addresses two issues:
gettext
Limitation, side-effects and discussion
It looks like part of this PR may be desired, as localisation is already in place---this mainly covers more of the strings (I'd say all the strings, but localisation does not always make sense).
However in the current approach I had to "deal" with f-strings and PyUpgrade, which may be undesired change for the project. On top of that it seems there is a bug in either Ruff or PyUpgrade in accepting ignore rules on multi-line commands. So a bunch of files get a file-global deactivation of the U032 rule, which means these files will not get checked for f-strings.
F-strings are assumedly desired, but given (1) PyBabel does not and may not support them, and (2) Click is library code, the project may (have to) accept the format method everywhere localisation is needed.
Recent discussions mention f-strings may work in PyBabel from Python 3.12. We did not confirm it, as we want to support down to the oldest supported Python3. So the changed proposed here may be transient for a couple years (then PyUpgrade may be reactivated and let work).
Related work
This PR only aims at localising more strings, so related to i18n issues.
On the way to this PR, we have considered a couple alternatives, notably trying to use the class API of Python's
gettext
. Some elements of discussion here may be useful to:In fact, Carmen's post helped solve an issue in using catalogues from different domains at runtime (thanks!).
Checklist on CONTRIBUTING
.. versionchanged::
entries in any relevant code docs.At submission time, nothing checked here, as first would like to make sure this PR target is acceptable (likely not as-is). The tox-based checks all pass, though (i.e. running the
tox
command returns all green, except the skipped tests).This PR supersedes #2890, because of a problem with GitHub.