[Python] Sphinx (Python) - How do I protect individual table cells of an external CSV file...

Discussão em 'Python' iniciado por Stack, Maio 22, 2025.

  1. Stack

    Stack Membro Participativo

    I use Sphinx (Python 3.13.3) and use the 'gettext' builder to create '.pot'/'.po' files.

    Certain cells in a . csv-table:: should not be translated (e.g. registry keys, enum values), but they may occur in other places and should be translated there. The word "Language" can occur in the text, but it can also be a registry value that occurs in a cell in a CSV table and should not be translated there.

    I asked ChatGPT about this and received the answer that I should define a small role in conf.py for this purpose that sets node[‘translatable’] = False. I thought the idea was actually quite good.

    # conf.py
    from docutils import nodes
    from docutils.parsers.rst import roles

    def notranslate_role(name, rawtext, text, lineno, inliner, **_):
    node = nodes.inline(text, text)
    node['translatable'] = False
    node['classes'].append('notranslate')
    return [node], []

    def setup(app):
    roles.register_local_role('notranslate', notranslate_role)


    .. csv-table::
    :header-rows: 1
    :delim: |

    Setting|Type|Description|Registry SubKey|Possible Values
    :notranslate:`Language`|:notranslate:`String`|Set the UI language|
    :notranslate:`MyApp\\ApplicationSettings`|
    :notranslate:`en,es,fr`


    Our expectation is that words marked with :notranslate: must not appear in the .pot file.

    But the actual status is that they still end up in the translation file (Msgids such as :notranslate:`Language).

    What am I doing wrong / what is still missing?

    Continue reading...

Compartilhe esta Página