Skip to content

Buttons cannot be rendered correctly if the content is translated by Gettext #263

@hwhsu1231

Description

@hwhsu1231

Describe the bug

context

When using the Sphinx i18n with gettext feature—specifically, generating .pot files via the gettext builder and then building the translated documentation using localized .po files with options for i18n—I found that the content of the button-ref and button-link directives fails to render correctly.

Take the following example code for reference:

.. button-ref:: index
   :color: primary
   :shadow:
   
   The content of the button-ref directive

The gettext builder successfully extracts the content "The content of the button-ref directive" as shown below:

#: ../../../index.rst:14
msgid "The content of the button-ref directive"
msgstr "button-ref 指示詞的內容"

However, applying the translated .po file breaks the expected button styling and navigation functionality. This issue persists in sphinx-design (version 0.7.0) regardless of whether reStructuredText or MyST Markdown syntax is used.

expectation

I expected the generated translated documentation to display the translated text within the button while maintaining the original CSS classes and hyperlinks:

<p>
  <a class="sd-sphinx-override sd-btn sd-text-wrap sd-btn-primary sd-shadow-sm reference internal" href="index.html">
    <span class="doc">button-ref 指示詞的內容</span>
  </a>
</p>

bug

Instead, the <a></a> and <span></span> tags for the button component disappear entirely for unknown reasons, leaving only the text:

<p>button-ref 指示詞的內容</p>

problem

This is a problem for people translating sphinx-based documentation with the i18n with gettext feature because the buttons will be broken.

Reproduce the bug

I have created a demo project, demo-sphinx-design-button-gettext. Just follow the instruction to build the original and translated documentation. The following is the screenshot:

Image

List your environment

The following outputs are printed with the pip list command:

Package                       Version
----------------------------- ----------
accessible-pygments           0.0.5
alabaster                     1.0.0
babel                         2.18.0
beautifulsoup4                4.14.3
certifi                       2026.2.25
charset-normalizer            3.4.6
click                         8.3.1
docutils                      0.22.4
furo                          2025.12.19
idna                          3.11
imagesize                     2.0.0
Jinja2                        3.1.6
markdown-it-py                4.0.0
MarkupSafe                    3.0.3
mdit-py-plugins               0.5.0
mdurl                         0.1.2
myst-parser                   5.0.0
packaging                     26.0
pip                           26.0.1
Pygments                      2.19.2
PyYAML                        6.0.3
requests                      2.32.5
roman-numerals                4.1.0
setuptools                    82.0.1
snowballstemmer               3.0.1
soupsieve                     2.8.3
Sphinx                        9.1.0
sphinx-basic-ng               1.0.0b2
sphinx_design                 0.7.0
sphinx-intl                   2.3.2
sphinxcontrib-applehelp       2.0.0
sphinxcontrib-devhelp         2.0.0
sphinxcontrib-htmlhelp        2.1.0
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          2.0.0
sphinxcontrib-serializinghtml 2.0.0
typing_extensions             4.15.0
urllib3                       2.6.3
wheel                         0.46.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions