pydata / pydata-sphinx-theme

A clean, three-column Sphinx theme with Bootstrap for the PyData community
https://pydata-sphinx-theme.readthedocs.io
BSD 3-Clause "New" or "Revised" License
557 stars 299 forks source link

gettext translations error #1840

Closed CptShooter closed 4 weeks ago

CptShooter commented 1 month ago

I'm having troubles to generate translations using your theme. Using this https://www.sphinx-doc.org/en/master/usage/advanced/intl.html#quick-guide

I have builded my project normally using this:

sphinx-build source build/html/en/dev -D language=en

When im running:

sphinx-build -b gettext source build/gettext/en/dev

Then error occurs:

Running Sphinx v7.3.7

Extension error (pydata_sphinx_theme.translator):
Handler <function setup_translators at 0x0000014FF4B231A0> for event 'builder-inited' threw an exception (exception: 'MessageCatalogBuilder' object has no attribute 'default_translator_class')

So I managed to skip that adding this to conf.py

from docutils import nodes

def setup(app):
    app.set_translator("docs", nodes.NodeVisitor)

After that it was almost good but now I'm getting this at the end of generation:

Extension error (pydata_sphinx_theme.pygments):
Handler <function overwrite_pygments_css at 0x0000026FE3A6EF20> for event 'build-finished' threw an exception (exception: [Errno 2] No such file or directory: 'D:\\Repository\\sphinx\\docs\\build\\gettext\\en\\dev\\_static\\pygments.css') 

After 3h I gave up. So my question is only, is this theme supports translations or I'm missing something in config?

trallard commented 1 month ago

Hey there 👋🏽 I am not sure I am following entirely, but are you trying to translate your project's documentation? As you have for example an English version, Spanish, Greek, and so on vs. Translation of the theme's components themselves?

If the former you might want to make sure the .po / locales path is properly set. Per the code snippets you shared I cannot see any direct references to your locales files/directories and / or wether the configuration needed in config.py is as expected

CptShooter commented 1 month ago

Yes I'm trying to translate my project's documentation (.rst files) using sphinx build-in commands.

sphinx-build -b gettext source build/gettext/en/dev

And that command is not working returning pydata_sphinx_theme exceptions.

trallard commented 1 month ago

This does not seem an issue with the PyData Sphinx Theme itself as we have no configurations or components that would directly affect translation or internationalization. This seems rather a misconfiguration of locale settings or .po files missing. These po files should contain the translations for your documentation site. Could you check against the Sphinx translation link you shared that these are correctly set on your end and that the locale directory for translations exist in the correct location?

CptShooter commented 1 month ago

This command should create .pot files, it's a first step. And it is problem with PyData Sphinx Theme. I've changed to Read the Docs Theme and command works fine.

trallard commented 1 month ago

Can you share the full tracelog for the command and not just the exception?

CptShooter commented 1 month ago
(venv) PS D:\Repository\sphinx\docs> sphinx-build -b gettext source build/gettext --show-traceback
Running Sphinx v7.3.7
loading pickled environment... done

Traceback (most recent call last):
  File "D:\Repository\sphinx\docs\venv\Lib\site-packages\sphinx\events.py", line 97, in emit
    results.append(listener.handler(self.app, *args))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Repository\sphinx\docs\venv\Lib\site-packages\pydata_sphinx_theme\translator.py", line 88, in setup_translators
    app.builder.default_translator_class,
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'MessageCatalogBuilder' object has no attribute 'default_translator_class'. Did you mean: 'get_translator_class'?

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\Repository\sphinx\docs\venv\Lib\site-packages\sphinx\cmd\build.py", line 332, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Repository\sphinx\docs\venv\Lib\site-packages\sphinx\application.py", line 268, in __init__
    self._init_builder()
  File "D:\Repository\sphinx\docs\venv\Lib\site-packages\sphinx\application.py", line 339, in _init_builder
    self.events.emit('builder-inited')
  File "D:\Repository\sphinx\docs\venv\Lib\site-packages\sphinx\events.py", line 108, in emit
    raise ExtensionError(
sphinx.errors.ExtensionError: Handler <function setup_translators at 0x000001A34C6B31A0> for event 'builder-inited' threw an exception (exception: 'MessageCatalogBuilder' object has no attribute 'default_translator_class')

Extension error (pydata_sphinx_theme.translator):
Handler <function setup_translators at 0x000001A34C6B31A0> for event 'builder-inited' threw an exception (exception: 'MessageCatalogBuilder' object has no attribute 'default_translator_class')
OriolAbril commented 4 weeks ago

I have tried to reproduce the issue and not been able to do it with the development version neither the latest version on pypi. Could you try and generate a more minimal example? Or share which versions and extensions are you using?

What I have used is https://github.com/OriolAbril/sphinx-playground/tree/f23fa85415258396b603c66d82cc0d2dff5d4c55. It has a single page but uses this theme and I am able to generate the .pot files without problem. Maybe there is an incompatibility with another extension or some kind of version incompatibility, but it looks like simply using the theme doesn't result in this error

CptShooter commented 4 weeks ago

Ok I see my mistake. I'have added

extensions = [ "pydata_sphinx_theme", ]

If you add this to your code, then You can replicate an error. I don't know why I kept adding it. Maybe because RTD Theme has it.

https://sphinx-rtd-theme.readthedocs.io/en/latest/installing.html

Without adding pydata_sphinx_theme to extensions it works fine.

Thanks