Skip to content

internationalization is not working for buttons #96

Closed

Description

@damian-krawczyk

Hi @chrisjsewell I would like to ask if this something which can be fixed in v0.4.0, or do you have any workaround/solution? :)

What I've found problematic for me is that the internationalization is not working for buttons - translated button changes to text (sphinx-panels has the same problem). Maybe I'm missing something to make it work for buttons?

Here I've build an example:

source page in English translated page in Polish
image image

button

source page with button in English

https://sphinx-internationalization-test.readthedocs.io/en/latest/#buttons

translation of button from English to Polish

https://github.com/damian-krawczyk/sphinx-internationalization-test/blob/ba6305e61eb3c57a050ff2064b70b82aa1fa93f0/docs/locale/pl/LC_MESSAGES/index.po#L37-L39

#: ../../index.rst:19 645df2e517a14ebe83fd8f2aa81331dd
msgid "Example button"
msgstr "Przykładowy przycisk"

translated page with button in Polish

https://sphinx-internationalization-test.readthedocs.io/pl/latest/#buttons

badge

source page with badge in English

https://sphinx-internationalization-test.readthedocs.io/en/latest/#badges

translation of badge from English to Polish

https://github.com/damian-krawczyk/sphinx-internationalization-test/blob/db2ac19c92d19a564070c03e7b9561d312d0c89d/docs/locale/pl/LC_MESSAGES/index.po#L45-L47

#: ../../index.rst:34 3651548d5be74a61ac96278b1ec9998d
msgid ":bdg-link-primary-line:`Example badge <https://example.com>`"
msgstr ":bdg-link-primary-line:`Przykładowa odznaka <https://example.com>`"

translated page with badge in Polish

https://sphinx-internationalization-test.readthedocs.io/pl/latest/#badges

Originally posted by @damian-krawczyk in #6 (comment)

Activity

  1. welcome commented on Aug 23, 2022

    @welcome

    Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

    If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.

    If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).

    Welcome to the EBP community! 🎉

  2. chrisjsewell commented on Aug 23, 2022

    @chrisjsewell
    Member

    Heya, well I'm happy to take PRs 🙏, but I'm not sure if will get round to figuring it out myself so soon

  3. jpmckinney commented on Dec 8, 2022

    @jpmckinney
    Contributor

    I thought maybe the extra inline might have been causing issues but even with code like (breaks buttons that contain non-plaintext - just for testing):

             if self.content:
    -            textnodes, _ = self.state.inline_text(
    -                "\n".join(self.content), self.lineno + self.content_offset
    -            )
    -            content = nodes.inline("", "")
    -            content.extend(textnodes)
    +            content = nodes.Text("\n".join(self.content))
             else:
    -            content = nodes.inline(target, target)
    +            content = nodes.Text(target)
             node.append(content)

    The above code generates what Sphinx references tend to look like, for the source (English) language:

                 <reference classes="sd-sphinx-override sd-btn sd-text-wrap" refuri="https://example.com">
    -                <inline>
    -                    Button text
    +                Button text

    But using @damian-krawczyk's project as an example, the reference seems to get entirely eliminated and only the text node is rendered in the translation...

    <paragraph>Przykładowy przycisk</paragraph>
  4. jpmckinney commented on Dec 8, 2022

    @jpmckinney
    Contributor

    Also, I don't know why Sphinx extracts :bdg-link-primary-line: as part of the translatable message for the badge.

  5. ferrine commented on Jul 14, 2023

    @ferrine

    Is there any progress on this?

  6. sneakers-the-rat commented on May 19, 2026

    @sneakers-the-rat
    Contributor

    as a temporary workaround, just using the generated html directly fixes the problem: pyOpenSci/python-package-guide#664 (comment)

    but that's pretty janky. I don't know docutils internals well enough to know what's going wrong with i18n here - the .po files seem to correctly extract the link text, it's just the outer DOM elements that get wreck'd

  7. added 4 commits that reference this issue on Jul 12, 2026
    9b26f54
    20bbe88
    65281b4
    834eebe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions