-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
gh-156360: Improve turtle translation support
#156422
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
Open
StanFromIreland
wants to merge
4
commits into
python:main
Choose a base branch
from
StanFromIreland:turtle/translations-plumbing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2688,12 +2688,48 @@ These modified docstrings are created automatically together with the function | |
| definitions that are derived from the methods at import time. | ||
|
|
||
|
|
||
| .. _turtle-docstring-translation: | ||
|
|
||
| Translation of docstrings into different languages | ||
| -------------------------------------------------- | ||
|
|
||
| There is a utility to create a dictionary the keys of which are the method names | ||
| and the values of which are the docstrings of the public methods of the classes | ||
| Screen and Turtle. | ||
| The docstrings of the public methods of the Screen and Turtle classes, and of | ||
| the functions derived from them, can be replaced by translations, so that | ||
| :func:`help` and IDE tooltips are shown in another language. | ||
|
|
||
| Translation catalogues can be installed from PyPI using the | ||
| :pypi:`turtle-translations` package, which holds the docstring dictionaries | ||
| for various languages. To use it, you must first install it with :program:`pip`:: | ||
|
|
||
| python -m pip install turtle-translations | ||
|
|
||
| The language is taken from the :envvar:`PYTHON_TURTLE_LANG` environment | ||
| variable, or, if that is unset, from the ``language`` entry of the | ||
| :file:`turtle.cfg` file. If no docstring dictionary is found for it, the | ||
| English docstrings are kept. | ||
|
|
||
| .. envvar:: PYTHON_TURTLE_LANG | ||
|
|
||
| The name of the language to read the docstring dictionary for. | ||
| Ignored when the :option:`-E` or :option:`-I` command line options are used. | ||
|
|
||
| .. versionadded:: 3.16 | ||
|
|
||
| A docstring dictionary is a module defining a dictionary named ``docsdict``, | ||
| the keys of which are method names such as ``Turtle.forward`` and the values of | ||
| which are the translated docstrings. It is looked up on :data:`sys.path`, first | ||
| as the submodule of that name of a package named :mod:`!turtle_translations`, | ||
| then as a top-level module named :samp:`turtle_docstringdict_{language}.py`, | ||
| and is read in at import time. Entries naming a method which does not exist in | ||
| the running version are ignored. | ||
|
|
||
| .. versionchanged:: 3.16 | ||
| The docstring dictionary may also be provided as a submodule of a | ||
| :mod:`!turtle_translations` package, and entries naming an unknown method | ||
| are ignored instead of reported. | ||
|
|
||
| To translate the docstrings into a language which is not available yet, write | ||
| out a template with :func:`write_docstringdict` and translate its values. | ||
|
|
||
| .. function:: write_docstringdict(filename="turtle_docstringdict") | ||
|
|
||
|
|
@@ -2705,17 +2741,6 @@ Screen and Turtle. | |
| Python script :file:`{filename}.py`. It is intended to serve as a template | ||
| for translation of the docstrings into different languages. | ||
|
|
||
| If you (or your students) want to use :mod:`!turtle` with online help in your | ||
| native language, you have to translate the docstrings and save the resulting | ||
| file as e.g. :file:`turtle_docstringdict_german.py`. | ||
|
|
||
| If you have an appropriate entry in your :file:`turtle.cfg` file this dictionary | ||
| will be read in at import time and will replace the original English docstrings. | ||
|
|
||
| At the time of this writing there are docstring dictionaries in German and in | ||
| Italian. (Requests please to [email protected].) | ||
|
|
||
|
|
||
|
|
||
| How to configure Screen and Turtles | ||
| ----------------------------------- | ||
|
|
@@ -2766,9 +2791,9 @@ Short explanation of selected entries: | |
| the cfg file). | ||
| - If you want to reflect the turtle its state, you have to use ``resizemode = | ||
| auto``. | ||
| - If you set e.g. ``language = italian`` the docstringdict | ||
| :file:`turtle_docstringdict_italian.py` will be loaded at import time (if | ||
| present on the import path, e.g. in the same directory as :mod:`!turtle`). | ||
| - The *language* entry selects the language of the docstrings, unless the | ||
| :envvar:`PYTHON_TURTLE_LANG` environment variable is set. See | ||
| :ref:`turtle-docstring-translation` for more information. | ||
| - The entries *exampleturtle* and *examplescreen* define the names of these | ||
| objects as they occur in the docstrings. The transformation of | ||
| method-docstrings to function-docstrings will delete these names from the | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
Misc/NEWS.d/next/Library/2026-08-26-15-28-59.gh-issue-156360.ctZMHf.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Add the :envvar:`PYTHON_TURTLE_LANG` environment variable to select the | ||
| language of :mod:`turtle` docstrings, and allow the docstring dictionary to | ||
| be provided as a submodule of the :pypi:`turtle-translations` package. | ||
| Entries naming a method which does not exist in the running version are now | ||
| ignored. |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.