executablebooks / sphinx-design

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

i18n: translating button-ref label results in loss of CSS classes #44

Open awvwgk opened 2 years ago

awvwgk commented 2 years ago

Describe the problem

CSS classes are dropped from button-ref when translating the label. The gettext replacement should only replace the button label rather than the complete directive creating the button.

Link to your repository or website

https://github.com/awvwgk/fpm-docs/blob/main/pages/index.md

Steps to reproduce

Steps to reproduce ``` ❯ cat index.md # Test :::{button-ref} ref :ref-type: ref :outline: Some text ::: (ref)= ## Header ❯ cat conf.py project = "test" extensions = [ "myst_parser", "sphinx_design", ] myst_enable_extensions = [ "colon_fence", "deflist", "substitution", "html_image", ] html_theme = "sphinx_book_theme" locale_dirs = ["locales/"] ❯ sphinx-build . _build/html -b html Running Sphinx v4.3.0 loading pickled environment... done myst v0.15.2: MdParserConfig(renderer='sphinx', commonmark_only=False, enable_extensions=['colon_fence', 'deflist', 'substitution', 'html_image'], dmath_allow_labels=True, dmath_allow_space=True, dmath_allow_digits=True, dmath_double_inline=False, update_mathjax=True, mathjax_classes='tex2jax_process|mathjax_process|math|output_area', disable_syntax=[], url_schemes=['http', 'https', 'mailto', 'ftp'], heading_anchors=None, heading_slug_func=None, html_meta=[], footnote_transition=True, substitutions=[], sub_delimiters=['{', '}'], words_per_minute=200) building [mo]: targets for 0 po files that are out of date building [html]: targets for 1 source files that are out of date updating environment: 0 added, 1 changed, 0 removed reading sources... [100%] index looking for now-outdated files... none found pickling environment... done checking consistency... done preparing documents... done writing output... [100%] index generating indices... genindex done writing additional pages... search done copying static files... done copying extra files... done dumping search index in English (code: en)... done dumping object inventory... done build succeeded. The HTML pages are in _build/html. ❯ cat locales/de/LC_MESSAGES/index.po # SOME DESCRIPTIVE TITLE. # Copyright (C) # This file is distributed under the same license as the test package. # FIRST AUTHOR , 2021. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: test \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-11-26 22:08+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.9.1\n" #: ../../index.md:1 msgid "Test" msgstr "" #: ../../index.md:3 msgid "Some text" msgstr "Irgendein Text" #: ../../index.md:12 msgid "Header" msgstr "Title" ❯ sphinx-build . _build/html/de -b html -Dlanguage=de Running Sphinx v4.3.0 loading translations [de]... done making output directory... done myst v0.15.2: MdParserConfig(renderer='sphinx', commonmark_only=False, enable_extensions=['colon_fence', 'deflist', 'substitution', 'html_image'], dmath_allow_labels=True, dmath_allow_space=True, dmath_allow_digits=True, dmath_double_inline=False, update_mathjax=True, mathjax_classes='tex2jax_process|mathjax_process|math|output_area', disable_syntax=[], url_schemes=['http', 'https', 'mailto', 'ftp'], heading_anchors=None, heading_slug_func=None, html_meta=[], footnote_transition=True, substitutions=[], sub_delimiters=['{', '}'], words_per_minute=200) building [mo]: targets for 1 po files that are out of date writing output... [100%] locales/de/LC_MESSAGES/index.mo building [html]: targets for 1 source files that are out of date updating environment: [new config] 1 added, 0 changed, 0 removed reading sources... [100%] index /home/awvwgk/projects/src/git/docu-fpm/test/index.md:3: WARNING: inconsistent term references in translated message. original: ['ref'], translated: [] looking for now-outdated files... none found pickling environment... done checking consistency... done preparing documents... done writing output... [100%] index generating indices... genindex done writing additional pages... search done copying static files... done copying extra files... done dumping search index in German (code: de)... done dumping object inventory... done build succeeded, 1 warning. The HTML pages are in _build/html/de. ```

Original document:

image

Translated button-ref:

image

The version of Python you're using

3.9.7

Your operating system

Linux

Versions of your packages

Environment file: https://github.com/awvwgk/fpm-docs/blob/main/environment.yaml

❯ mamba info

                  __    __    __    __
                 /  \  /  \  /  \  /  \
                /    \/    \/    \/    \
███████████████/  /██/  /██/  /██/  /████████████████████████
              /  / \   / \   / \   / \  \____
             /  /   \_/   \_/   \_/   \    o \__,
            / _/                       \_____/  `
            |/
        ███╗   ███╗ █████╗ ███╗   ███╗██████╗  █████╗
        ████╗ ████║██╔══██╗████╗ ████║██╔══██╗██╔══██╗
        ██╔████╔██║███████║██╔████╔██║██████╔╝███████║
        ██║╚██╔╝██║██╔══██║██║╚██╔╝██║██╔══██╗██╔══██║
        ██║ ╚═╝ ██║██║  ██║██║ ╚═╝ ██║██████╔╝██║  ██║
        ╚═╝     ╚═╝╚═╝  ╚═╝╚═╝     ╚═╝╚═════╝ ╚═╝  ╚═╝

        mamba (0.17.0) supported by @QuantStack

        GitHub:  https://github.com/mamba-org/mamba
        Twitter: https://twitter.com/QuantStack

█████████████████████████████████████████████████████████████

     active environment : sphinx
    active env location : /home/awvwgk/software/opt/conda/envs/sphinx
            shell level : 2
       user config file : /home/awvwgk/.condarc
 populated config files : /home/awvwgk/software/opt/conda/.condarc
          conda version : 4.10.3
    conda-build version : not installed
         python version : 3.9.6.final.0
       virtual packages : __linux=5.10.70=0
                          __glibc=2.33=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : /home/awvwgk/software/opt/conda  (writable)
      conda av data dir : /home/awvwgk/software/opt/conda/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /home/awvwgk/software/opt/conda/pkgs
                          /home/awvwgk/.conda/pkgs
       envs directories : /home/awvwgk/software/opt/conda/envs
                          /home/awvwgk/.conda/envs
               platform : linux-64
             user-agent : conda/4.10.3 requests/2.26.0 CPython/3.9.6 Linux/5.10.70-1-MANJARO manjaro/21.1.6 glibc/2.33
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False

❯ mamba list
# packages in environment at /home/awvwgk/software/opt/conda/envs/sphinx:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       1_gnu    conda-forge
ablog                     0.10.20            pyhd8ed1ab_0    conda-forge
alabaster                 0.7.12                     py_0    conda-forge
argh                      0.26.2          pyh9f0ad1d_1002    conda-forge
async_generator           1.10                       py_0    conda-forge
attrs                     21.2.0             pyhd8ed1ab_0    conda-forge
babel                     2.9.1              pyh44b312d_0    conda-forge
beautifulsoup4            4.10.0             pyha770c72_0    conda-forge
bleach                    4.1.0              pyhd8ed1ab_0    conda-forge
brotlipy                  0.7.0           py39h3811e60_1003    conda-forge
ca-certificates           2021.10.8            ha878542_0    conda-forge
certifi                   2021.10.8        py39hf3d152e_1    conda-forge
cffi                      1.15.0           py39h4bc2ebd_0    conda-forge
chardet                   4.0.0            py39hf3d152e_2    conda-forge
charset-normalizer        2.0.8              pyhd8ed1ab_0    conda-forge
click                     7.1.2              pyh9f0ad1d_0    conda-forge
colorama                  0.4.4              pyh9f0ad1d_0    conda-forge
cryptography              36.0.0           py39h95dcef6_0    conda-forge
dataclasses               0.8                pyhc8e2a94_3    conda-forge
defusedxml                0.7.1              pyhd8ed1ab_0    conda-forge
docutils                  0.16             py39hf3d152e_3    conda-forge
entrypoints               0.3             py39hde42818_1002    conda-forge
feedgen                   0.9.0              pyh9f0ad1d_0    conda-forge
furo                      2021.10.9          pyhd8ed1ab_0    conda-forge
icu                       69.1                 h9c3ff4c_0    conda-forge
idna                      3.1                pyhd3deb0d_0    conda-forge
imagesize                 1.3.0              pyhd8ed1ab_0    conda-forge
importlib-metadata        4.8.2            py39hf3d152e_0    conda-forge
importlib_resources       3.3.1            py39hf3d152e_0    conda-forge
invoke                    1.6.0              pyhd8ed1ab_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
jinja2                    3.0.3              pyhd8ed1ab_0    conda-forge
jsonschema                4.2.1              pyhd8ed1ab_0    conda-forge
jupyter_client            7.1.0              pyhd8ed1ab_0    conda-forge
jupyter_core              4.9.1            py39hf3d152e_1    conda-forge
jupyterlab_pygments       0.1.2              pyh9f0ad1d_0    conda-forge
latexcodec                2.0.1              pyh9f0ad1d_0    conda-forge
ld_impl_linux-64          2.36.1               hea4e1c9_2    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-ng                 11.2.0              h1d223b6_11    conda-forge
libgomp                   11.2.0              h1d223b6_11    conda-forge
libiconv                  1.16                 h516909a_0    conda-forge
libsodium                 1.0.18               h36c2ea0_1    conda-forge
libstdcxx-ng              11.2.0              he4da1e4_11    conda-forge
libxml2                   2.9.12               h885dcf4_1    conda-forge
libxslt                   1.1.33               h0ef7038_3    conda-forge
libzlib                   1.2.11            h36c2ea0_1013    conda-forge
lxml                      4.6.4            py39h107f48f_0    conda-forge
markdown-it-py            1.1.0              pyhd8ed1ab_0    conda-forge
markupsafe                2.0.1            py39h3811e60_1    conda-forge
mdit-py-plugins           0.2.8              pyhd8ed1ab_0    conda-forge
mistune                   0.8.4           py39h3811e60_1005    conda-forge
myst-parser               0.15.2             pyhd8ed1ab_0    conda-forge
nbclient                  0.5.9              pyhd8ed1ab_0    conda-forge
nbconvert                 6.3.0            py39hf3d152e_1    conda-forge
nbformat                  5.1.3              pyhd8ed1ab_0    conda-forge
nbsphinx                  0.8.7              pyhd8ed1ab_0    conda-forge
ncurses                   6.2                  h58526e2_4    conda-forge
nest-asyncio              1.5.1              pyhd8ed1ab_0    conda-forge
openssl                   1.1.1l               h7f98852_0    conda-forge
packaging                 21.3               pyhd8ed1ab_0    conda-forge
pandoc                    2.16.2               h7f98852_0    conda-forge
pandocfilters             1.5.0              pyhd8ed1ab_0    conda-forge
pip                       21.3.1             pyhd8ed1ab_0    conda-forge
pybtex                    0.24.0           py39hf3d152e_1    conda-forge
pybtex-docutils           1.0.1            py39hf3d152e_1    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pydata-sphinx-theme       0.7.2              pyhd8ed1ab_0    conda-forge
pygments                  2.10.0             pyhd8ed1ab_0    conda-forge
pyopenssl                 21.0.0             pyhd8ed1ab_0    conda-forge
pyparsing                 3.0.6              pyhd8ed1ab_0    conda-forge
pyrsistent                0.18.0           py39h3811e60_0    conda-forge
pysocks                   1.7.1            py39hf3d152e_4    conda-forge
python                    3.9.7           hb7a2778_3_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python_abi                3.9                      2_cp39    conda-forge
pytz                      2021.3             pyhd8ed1ab_0    conda-forge
pyyaml                    6.0              py39h3811e60_3    conda-forge
pyzmq                     22.3.0           py39h37b5a0c_1    conda-forge
readline                  8.1                  h46c0cb4_0    conda-forge
requests                  2.26.0             pyhd8ed1ab_1    conda-forge
setuptools                59.2.0           py39hf3d152e_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
snowballstemmer           2.2.0              pyhd8ed1ab_0    conda-forge
soupsieve                 2.3                pyhd8ed1ab_0    conda-forge
sphinx                    4.3.0              pyh6c4a22f_0    conda-forge
sphinx-book-theme         0.1.7              pyhd8ed1ab_0    conda-forge
sphinx-copybutton         0.4.0              pyhd8ed1ab_0    conda-forge
sphinx-design             0.0.13             pyhd8ed1ab_0    conda-forge
sphinx-inline-tabs        2021.8.17b10       pyhd8ed1ab_0    conda-forge
sphinx-intl               2.0.1              pyhd8ed1ab_0    conda-forge
sphinx-panels             0.6.0              pyhd8ed1ab_0    conda-forge
sphinx-togglebutton       0.2.3              pyhd3deb0d_0    conda-forge
sphinx_rtd_theme          1.0.0              pyhd8ed1ab_0    conda-forge
sphinxcontrib-applehelp   1.0.2                      py_0    conda-forge
sphinxcontrib-bibtex      2.4.1              pyhd8ed1ab_0    conda-forge
sphinxcontrib-devhelp     1.0.2                      py_0    conda-forge
sphinxcontrib-htmlhelp    2.0.0              pyhd8ed1ab_0    conda-forge
sphinxcontrib-jsmath      1.0.1                      py_0    conda-forge
sphinxcontrib-qthelp      1.0.3                      py_0    conda-forge
sphinxcontrib-serializinghtml 1.1.5              pyhd8ed1ab_1    conda-forge
sqlite                    3.36.0               h9cd32fc_2    conda-forge
testpath                  0.5.0              pyhd8ed1ab_0    conda-forge
tk                        8.6.11               h27826a3_1    conda-forge
tornado                   6.1              py39h3811e60_2    conda-forge
traitlets                 5.1.1              pyhd8ed1ab_0    conda-forge
typing_extensions         4.0.0              pyha770c72_0    conda-forge
tzdata                    2021e                he74cb21_0    conda-forge
urllib3                   1.26.7             pyhd8ed1ab_0    conda-forge
watchdog                  2.1.6            py39hf3d152e_1    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.37.0             pyhd8ed1ab_1    conda-forge
xz                        5.2.5                h516909a_1    conda-forge
yaml                      0.2.5                h516909a_0    conda-forge
zeromq                    4.3.4                h9c3ff4c_1    conda-forge
zipp                      3.6.0              pyhd8ed1ab_0    conda-forge
zlib                      1.2.11            h36c2ea0_1013    conda-forge

Additional context

No response

awvwgk commented 2 years ago

I would be interested in contributing a fix for this issue. What would be a good place to start looking for the source of this problem?

awvwgk commented 2 years ago

Poking around a bit I found that a button-ref without content can be translated just fine

:::{button-ref} ref
:ref-type: ref
:outline:
:::

While having content will result in the above behaviour

:::{button-ref} ref
:ref-type: ref
:outline:

Some text
:::

Therefore, my naive guess would be that this is related to the way the content added. Would the piece linked below be the right place to start looking?

https://github.com/executablebooks/sphinx-design/blob/6a412a18abe310b0ceba258a2867bd183214cc27/sphinx_design/badges_buttons.py#L180-L187

OriolAbril commented 1 year ago

I'd also like to help get this fixed. Are there any resources you could point me on handling translations with directives? Or an existing workaround that needs testing?

jpmckinney commented 1 year ago

Related: #96

ferrine commented 1 year ago

Hey there, any progress on this?

ferrine commented 1 year ago

Hi, @OriolAbril, nice to see you in the thread