sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.61k stars 2.13k forks source link

locale_dirs default value inconsistency #13025

Closed rffontenelle closed 1 month ago

rffontenelle commented 1 month ago

Describe the bug

sphinx-build searches for translation files in the directory 'locale', even though locale_dirs conf value defaults to 'locales' since Sphinx 1.5, as per changelog entry.

This causes weird behaviors like sphinx-intl looking for translations in 'locales' (https://github.com/sphinx-doc/sphinx-intl/issues/14), but sphinx-build builds translated docs using translations from 'locale'.

Related code (I think, not sure though):

https://github.com/sphinx-doc/sphinx/blob/a1510de4777eaa2e569435f95b05f6f3293d7035/sphinx/application.py#L321

https://github.com/sphinx-doc/sphinx/blob/a1510de4777eaa2e569435f95b05f6f3293d7035/sphinx/config.py#L217

How to Reproduce

# Get sphinx and sphinx-doc-translations sources
git clone --single-branch --depth 1 --branch 3.13 https://github.com/python/cpython
git clone --single-branch --depth 1 --branch 3.13 https://github.com/python/python-docs-pt-br cpython/Doc/locale/pt_BR/LC_MESSAGES
# Enter sphinx dir
cd cpython/Doc
# Build translated from locale
make html SPHINXOPTS='-Dlanguage=pt_BR'
# and check built files, should be translated
# Now rename directory
mv locale locales
# Again build translated from locale
make html SPHINXOPTS='-Dlanguage=pt_BR'
# and check the built files, which should NOT be translated now.

Environment Information

Latest sphinx commit

Sphinx extensions

No response

Additional context

No response

AA-Turner commented 1 month ago

locale_dirs += [path.join(package_dir, 'locale')] is using the Sphinx sphinx.locale directory as a final fallback, so I think unrelated.

rffontenelle commented 1 month ago

@AA-Turner I see. So the usage/configuration page that says locale_dirs defaults to 'locales' is incorrect, right?

AA-Turner commented 1 month ago

config.locale_dirs defaults to ['locales']

When I try and run locally with the .mo files under Doc/locales/pt_BR/LC_MESSAGES, I get translated results. When under Doc/locale, I don't.

This seems opposite to your reproducer @rffontenelle?

A

rffontenelle commented 1 month ago

It doesn't, hence my original statement is incorrect (now?). Proposed a fix for the Configuration page that is currently stating 'locale' is the default.