executablebooks / sphinx-design

A sphinx extension for designing beautiful, screen-size responsive web components.
https://sphinx-design.readthedocs.io/en/furo-theme/
MIT License
194 stars 60 forks source link

internationalization is not working for buttons #96

Open damian-krawczyk opened 2 years ago

damian-krawczyk commented 2 years ago

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 https://github.com/executablebooks/sphinx-design/issues/6#issuecomment-903299075

welcome[bot] commented 2 years ago

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
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! :tada:

chrisjsewell commented 2 years ago

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

jpmckinney commented 1 year ago

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>
jpmckinney commented 1 year ago

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

ferrine commented 1 year ago

Is there any progress on this?