-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -105,6 +105,7 @@ | |
| import inspect | ||
| import sys | ||
|
|
||
| from os import environ | ||
| from os.path import isfile, split, join | ||
| from pathlib import Path | ||
| from contextlib import contextmanager | ||
|
|
@@ -4017,18 +4018,31 @@ def read_docstrings(lang): | |
| Transfer docstrings, translated to lang, from a dictionary-file | ||
| to the methods of classes Screen and Turtle and - in revised form - | ||
| to the corresponding functions. | ||
|
|
||
| The dictionary is looked up as the submodule lang of the package | ||
| turtle_translations, then as the top-level module | ||
| turtle_docstringdict_lang. | ||
|
|
||
| Entries naming a method which does not exist in this version are | ||
| ignored. | ||
| """ | ||
| modname = "turtle_docstringdict_%(language)s" % {'language':lang.lower()} | ||
| module = __import__(modname) | ||
| import importlib | ||
| lang = lang.lower() | ||
| try: | ||
| module = importlib.import_module("turtle_translations.%s" % lang) | ||
|
Contributor
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. Could the new PyPI integration use non-executable catalogues, such as gettext Since this package is intended to provide translation data, we could use The existing top-level Python-module format could remain as a legacy compatibility path.
Member
Author
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. That's possible, but I'm also going to defer that discussion for now. I'd like to have
Contributor
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. Converting the translation data may be straightforward, but I think the compatibility cost lies in changing the consumer contract after a CPython release has shipped. Once a released loader imports Also, converting the current dictionary to a message gettext catalogue would require the original English docstrings, which the dictionary itself does not preserve. Would it make sense to use PO/MO as the source format from the start, while generating docsdict modules for the initial loader? That would allow the package to exist now without making the legacy runtime format the canonical translation format.
Member
Author
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.
Thankfully we still have 8 months till the feature freeze to figure this out.
Let's discuss once we have a repository to work in. |
||
| except ModuleNotFoundError: | ||
| module = importlib.import_module("turtle_docstringdict_%s" % lang) | ||
| docsdict = module.docsdict | ||
| for key in docsdict: | ||
| try: | ||
| # eval(key).im_func.__doc__ = docsdict[key] | ||
| eval(key).__doc__ = docsdict[key] | ||
| except AttributeError: | ||
| pass | ||
| except Exception: | ||
| print("Bad docstring-entry: %s" % key) | ||
|
|
||
| _LANGUAGE = _CFG["language"] | ||
| _LANGUAGE = environ.get("PYTHON_TURTLE_LANG") or _CFG["language"] | ||
|
Contributor
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. Since this is a |
||
|
|
||
| try: | ||
| if _LANGUAGE != "english": | ||
|
|
||
| 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. |
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.
Since the Discourse discussion has not yet reached consensus on bundling, could we avoid the categorical statement “The translations are not part of Python”? Perhaps this could simply say: “Translation catalogues can be installed from PyPI using the turtle-translations package.” This would document the mechanism introduced by this PR without deciding whether some catalogues may also be bundled with Python in the future.
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.
This is still a draft, I'll update once the discussion has settled.