-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Allow internationalization of 'conf.py' #1260
Comments
I want to raise this topic. I also have the need for translation in the For example, the I tried the following in my
When I run
|
I have a document in two languages and they both have the same English title. I need translated titles. Here are the examples: |
as a workaround for sphinx-doc/sphinx#1260 we make a call to the underlying gettext module to load the translations in the conf.py config file. Translations are extracted by xgettext and joined with the existing ones.
I have created a workaround for this and it works in all situations I need. But it is still an ugly workaround. # lazy_format.py
class LazyFormat(str):
def __new__(cls, msg: str, *args, **kwargs):
instance = super().__new__(cls, msg)
instance._lazy_msg = msg
instance._lazy_args = args
instance._lazy_kwargs = kwargs
return instance
def __str__(self):
return self._lazy_msg.format(*self._lazy_args, **self._lazy_kwargs) You must place this in some other file then config.py and then import it or you will just get pickeling error. This class will postpone the string rendering to the latest possible state so you can later do in # conf.py
from sphinx.locale import _
from lazy_format import LazyFormat
project = LazyFormat(_('My document title in English'))
copyright = LazyFormat(_('© {year}. Version {version} {author}'), year=2024, version="1.0", author="me") Then just create msgid "My document title in English"
msgstr "Mia dokumenttitolo en Esperanto"
msgid "© {year}. Version {version} {author}"
msgstr "© {year}. Versio {version} {author}" |
It could be usefull to add a new POT template for marked as translatable strings in 'conf.py' file.
Hi, Sphinx team.
At least in version 1.1.3, 'gettext' builder only creates POT templates for reStructuredText documents. But some configuration options, defined in 'conf.py', also need to be translated, in order to enhance translatability of all parts of a given documentation.
For example, such a need occurs at least for:
It should be possible to let mark all desirable strings with '_()', where choice could all fall at project's discretion. 'gettext' builder then could generate a dedicated POT file, letting translators add translations for these strings. (I'm not sure of last step, for generation of e.g. HTML built files, with such a modified 'conf.py'.)
What do you guys think about this idea, and then about its feasability?
The text was updated successfully, but these errors were encountered: