Skip to content
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

locale/<language>/LC_MESSAGES/sphinx.po translation ignored #6640

Closed
jonascj opened this issue Aug 13, 2019 · 6 comments
Closed

locale/<language>/LC_MESSAGES/sphinx.po translation ignored #6640

jonascj opened this issue Aug 13, 2019 · 6 comments

Comments

@jonascj
Copy link

jonascj commented Aug 13, 2019

Describe the bug
I read [1] as it should be possible to add a file locale/<language>/LC_MESSAGES/sphinx.mo to the source dir (same dir as the Makefile) and through that change translations or add additional translation to .

When I add locale/da/LC_MESSAGES/sphinx.po, with updated entries for Fig. %s and Listing %s, a locale/da/LC_MESSAGES/sphinx.mo is created (because of gettext_auto_build = True), but the translations are not used. The translations from the official da translation [2] is used. Of course language = 'da' is in conf.py.

[1] http://www.sphinx-doc.org/en/master/usage/configuration.html#confval-locale_dirs
[2] https://github.com/sphinx-doc/sphinx/blob/master/sphinx/locale/da/LC_MESSAGES/sphinx.po

To Reproduce
Steps to reproduce the behavior:

$ git clone https://github.com/jonascj/sphinx-test-locale-override.git
$ cd sphinx-test-locale-override
$ git checkout 8dea4cd # EDIT: current master showcases workaround, so revert back to see the bug
$ # make python venv however you like
$ pip install sphinx
$ make html

Notice that locale/da/LC_MESSAGES/sphinx.mo has been created. Open _build/html/index.html.

Expected behavior
The caption label for the figure figur 1 should have been Foobar 1 (for the sake of testing) and the caption label for the code block Viser 1 should have been Whatever 1 (again for the sake of testing).

Your project
https://github.com/jonascj/sphinx-test-locale-override.git

Screenshots
Screenshot of index.html

Environment info

  • OS: Arch Linux
  • Python version: 3.7.3
  • Sphinx version: 2.1.2
  • Sphinx extensions: none
  • Extra tools: none
@jonascj
Copy link
Author

jonascj commented Aug 13, 2019

So I found a work around or "proved" to myself that I didn't read the instructions completely wrong.
If I just change language='da' to language='en' in conf.py and rename locale/da/ to locale/en/ it works as expected. My few select changes to the translation of internal messages are show.

$ git clone https://github.com/jonascj/sphinx-test-locale-override.git
$ cd sphinx-test-locale-override
$ # make python venv however you like
$ pip install sphinx
$ make html

Open _build/html/index.html. Notice how the figure caption label is now Foobar (for testing) and the code block caption label Whatever, as expected.

Screenshot of index.html

Of course now the rest of the internal messages are in English and I needed them in Danish. But that is also easily worked around. Just obtain a copy of the published or packaged locale/da/LC_MESSAGES/sphinx.po [1], rename it to locale/en/LC_MESSAGES/sphinx.po and change any messages wanting change. Semantically it is not pretty, since the config says it is English, but the html output will be as desired (Danish translations with a few changes).

Maybe it is related to this, I am not completely sure: #1242

If it is not a bug, it is at least unexpected behavior . If furt,her are needed to make it work (without my workaround) the documentation should be updated to mention it [2]

[1] https://github.com/sphinx-doc/sphinx/blob/master/sphinx/locale/da/LC_MESSAGES/sphinx.po
[2] http://www.sphinx-doc.org/en/master/usage/configuration.html#confval-locale_dirs

@tk0miya
Copy link
Member

tk0miya commented Aug 13, 2020

At present, ${locale_dirs}/{language}/LC_MESSAGES/sphinx.mo is only used if failed to look the message up from the system's message catalog.

@shimizukawa Which is correct the behavior or document?

@tk0miya tk0miya added this to the 3.3.0 milestone Aug 13, 2020
@shimizukawa
Copy link
Member

I'm not sure which is correct. IMO, it is better to override the system values with the intentionally provided sphinx.mo file.

@tk0miya
Copy link
Member

tk0miya commented Aug 14, 2020

@shimizukawa Thank you for comment. I'll change the priority of users' message catalog later.

tk0miya added a commit to tk0miya/sphinx that referenced this issue Aug 14, 2020
Our document describes that users can override system messages via
their own message catalog named `sphinx.mo` under the locale_dirs.
But it has not been used since its beginning of i18n mechanism because
the priority of users' message catalog is lower than system's.

This makes the priority of users' message catalog higher than system's.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Oct 4, 2020
Our document describes that users can override system messages via
their own message catalog named `sphinx.mo` under the locale_dirs.
But it has not been used since its beginning of i18n mechanism because
the priority of users' message catalog is lower than system's.

This makes the priority of users' message catalog higher than system's.
@tk0miya tk0miya closed this as completed in 37235c7 Oct 4, 2020
tk0miya added a commit that referenced this issue Oct 4, 2020
…essage

Fix #6640: i18n: Failed to override system message translation
@dbitouze
Copy link

dbitouze commented Feb 1, 2021

Is there a way to provide a custom sphinx.mo file in the source directory? I ask because I'm currently building the html pages via GitLab pages where, AFAIK, it is not possible to customize what's in the locale dirs.

@tk0miya
Copy link
Member

tk0miya commented Feb 1, 2021

@dbitouze You can do it. Please read the document of locale_dirs and i18n. You can change the locale dirs via settings.
https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-locale_dirs
https://www.sphinx-doc.org/en/master/usage/advanced/intl.html

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants