How to translate the content of the 'parsed-literal' directive of Sphinx if there exist hyperlinks?

58 Views Asked by At

Problem Description

Recently, I tried to build the CMake documentation with its gettext .po files generated by the gettext builder. However, I wonder how to translate the content of the parsed-literal directive if there exist hyperlinks?

Take this part for example. Normally, we should translate hyperlinks in .rst like the following: (right?)

# Source (msgid)
`Build a Project`_

# Translation (msgstr)
`建置專案 <Build a Project_>`_

However, after running sphinx-build to build the HTML documentation with this translation, the hyperlinks are broken. And there is a warning message:

/home/hwhsu1231/Repo/testing/cmake-v3.28.4/Help/manual/cmake.1.rst:11: WARNING: inconsistent references in translated message. original: ['Generate a Project Buildsystem', 'Build a Project', 'Install a Project', 'Open a Project', 'Run a Script', 'Run a Command-Line Tool', 'Run the Find-Package Tool', 'Run a Workflow Preset', 'View Help_'], translated: []

What happened? How to fix it?

How to Reproduce

  1. Download the demo project:

    https://www.terabox.com/taiwan/sharing/link?surl=5okvTcrcnl4gO_i1mW6nJw

  2. Run the following commands in order:

    tar -zxf cmake-v3.28.4.tar.gz
    cd cmake-v3.28.4
    python -m venv .venv
    source .venv/bin/activate
    pip install sphinx==6.2.1 --progress-bar off
    LANG=en_US.UTF-8 sphinx-build -b html -D locale_dirs=locale -D language=zh_TW -D gettext_compact=0 -D gettext_additional_targets=index,literal-block Help _build
    firefox _build/manual/cmake.1.html
    

Environment Information

Platform:              linux; (Linux-6.5.0-26-generic-x86_64-with-glibc2.35)
Python version:        3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0])
Python implementation: CPython
Sphinx version:        6.2.1
Docutils version:      0.19
Jinja2 version:        3.1.3
Pygments version:      2.17.2

Additional Contexts

The full log of 'How to Reproduce' is as below:

hwhsu1231@vb-kubuntu:~/Repo/testing$ tar -zxf cmake-v3.28.4.tar.gz
hwhsu1231@vb-kubuntu:~/Repo/testing$ cd cmake-v3.28.4
hwhsu1231@vb-kubuntu:~/Repo/testing/cmake-v3.28.4$ python -m venv .venv
hwhsu1231@vb-kubuntu:~/Repo/testing/cmake-v3.28.4$ source .venv/bin/activate
(.venv) hwhsu1231@vb-kubuntu:~/Repo/testing/cmake-v3.28.4$ pip install sphinx==6.2.1 --progress-bar off
Collecting sphinx==6.2.1
  Using cached sphinx-6.2.1-py3-none-any.whl (3.0 MB)
Collecting packaging>=21.0
  Using cached packaging-24.0-py3-none-any.whl (53 kB)
Collecting sphinxcontrib-htmlhelp>=2.0.0
  Using cached sphinxcontrib_htmlhelp-2.0.5-py3-none-any.whl (99 kB)
Collecting alabaster<0.8,>=0.7
  Using cached alabaster-0.7.16-py3-none-any.whl (13 kB)
Collecting requests>=2.25.0
  Using cached requests-2.31.0-py3-none-any.whl (62 kB)
Collecting sphinxcontrib-applehelp
  Using cached sphinxcontrib_applehelp-1.0.8-py3-none-any.whl (120 kB)
Collecting docutils<0.20,>=0.18.1
  Using cached docutils-0.19-py3-none-any.whl (570 kB)
Collecting Jinja2>=3.0
  Using cached Jinja2-3.1.3-py3-none-any.whl (133 kB)
Collecting babel>=2.9
  Using cached Babel-2.14.0-py3-none-any.whl (11.0 MB)
Collecting sphinxcontrib-qthelp
  Using cached sphinxcontrib_qthelp-1.0.7-py3-none-any.whl (89 kB)
Collecting sphinxcontrib-jsmath
  Using cached sphinxcontrib_jsmath-1.0.1-py2.py3-none-any.whl (5.1 kB)
Collecting imagesize>=1.3
  Using cached imagesize-1.4.1-py2.py3-none-any.whl (8.8 kB)
Collecting Pygments>=2.13
  Using cached pygments-2.17.2-py3-none-any.whl (1.2 MB)
Collecting sphinxcontrib-devhelp
  Using cached sphinxcontrib_devhelp-1.0.6-py3-none-any.whl (83 kB)
Collecting snowballstemmer>=2.0
  Using cached snowballstemmer-2.2.0-py2.py3-none-any.whl (93 kB)
Collecting sphinxcontrib-serializinghtml>=1.1.5
  Using cached sphinxcontrib_serializinghtml-1.1.10-py3-none-any.whl (92 kB)
Collecting MarkupSafe>=2.0
  Using cached MarkupSafe-2.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Collecting charset-normalizer<4,>=2
  Using cached charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142 kB)
Collecting urllib3<3,>=1.21.1
  Using cached urllib3-2.2.1-py3-none-any.whl (121 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2024.2.2-py3-none-any.whl (163 kB)
Collecting idna<4,>=2.5
  Using cached idna-3.6-py3-none-any.whl (61 kB)
Installing collected packages: snowballstemmer, urllib3, sphinxcontrib-serializinghtml, sphinxcontrib-qthelp, sphinxcontrib-jsmath, sphinxcontrib-htmlhelp, sphinxcontrib-devhelp, sphinxcontrib-applehelp, Pygments, packaging, MarkupSafe, imagesize, idna, docutils, charset-normalizer, certifi, babel, alabaster, requests, Jinja2, sphinx
Successfully installed Jinja2-3.1.3 MarkupSafe-2.1.5 Pygments-2.17.2 alabaster-0.7.16 babel-2.14.0 certifi-2024.2.2 charset-normalizer-3.3.2 docutils-0.19 idna-3.6 imagesize-1.4.1 packaging-24.0 requests-2.31.0 snowballstemmer-2.2.0 sphinx-6.2.1 sphinxcontrib-applehelp-1.0.8 sphinxcontrib-devhelp-1.0.6 sphinxcontrib-htmlhelp-2.0.5 sphinxcontrib-jsmath-1.0.1 sphinxcontrib-qthelp-1.0.7 sphinxcontrib-serializinghtml-1.1.10 urllib3-2.2.1
(.venv) hwhsu1231@vb-kubuntu:~/Repo/testing/cmake-v3.28.4$ LANG=en_US.UTF-8 sphinx-build -b html -D locale_dirs=locale -D language=zh_TW -D gettext_compact=0 -D gettext_additional_targets=index,literal-block Help _build
Running Sphinx v6.2.1
loading translations [zh_TW]... done
making output directory... done
building [mo]: targets for 0 po files that are out of date
writing output... 
building [html]: targets for 1997 source files that are out of date
updating environment: [new config] 1997 added, 0 changed, 0 removed
reading sources... [100%] variable/XCODE_VERSION                                                                                                                                           
/home/hwhsu1231/Repo/testing/cmake-v3.28.4/Help/manual/cmake.1.rst:11: WARNING: inconsistent references in translated message. original: ['`Generate a Project Buildsystem`_', '`Build a Project`_', '`Install a Project`_', '`Open a Project`_', '`Run a Script`_', '`Run a Command-Line Tool`_', '`Run the Find-Package Tool`_', '`Run a Workflow Preset`_', '`View Help`_'], translated: []
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] variable/XCODE_VERSION                                                                                                                                            
generating indices... genindex done
writing additional pages... search done
copying images... [100%] guide/user-interaction/GUI-Add-Entry.png                                                                                                                          
copying downloadable files... [100%] manual/presets/schema.json                                                                                                                            
copying static files... done
copying extra files... done
dumping search index in Chinese (code: zh)... done
dumping object inventory... done
build succeeded, 1 warning.

The HTML pages are in _build.
(.venv) hwhsu1231@vb-kubuntu:~/Repo/testing/cmake-v3.28.4$ firefox _build/manual/cmake.1.html
[Parent 3713910, Main Thread] WARNING: Theme parsing error: gtk.css:1:21: Failed to import: 開啟檔案 /home/hwhsu1231/snap/firefox/4033/.config/gtk-3.0/colors.css 時發生錯誤:No such file or directory: 'glib warning', file /build/firefox/parts/firefox/build/toolkit/xre/nsSigHandlers.cpp:187

(firefox:3713910): Gtk-WARNING **: 21:36:38.123: Theme parsing error: gtk.css:1:21: Failed to import: 開啟檔案 /home/hwhsu1231/snap/firefox/4033/.config/gtk-3.0/colors.css 時發生錯誤:No such file or directory
Gtk-Message: 21:36:38.157: Failed to load module "colorreload-gtk-module"
Gtk-Message: 21:36:38.157: Failed to load module "window-decorations-gtk-module"
ATTENTION: default value of option mesa_glthread overridden by environment.
ATTENTION: default value of option mesa_glthread overridden by environment.
^CExiting due to channel error.
Exiting due to channel error.
Exiting due to channel error.
Exiting due to channel error.
Exiting due to channel error.
Exiting due to channel error.

(.venv) hwhsu1231@vb-kubuntu:~/Repo/testing/cmake-v3.28.4$ 

Compared with the offical documentation (cmake.1.html), the following screenshot is what I built. As we can see, the hyperlinks are broken.

Preview the cmake.1.html built with translations

0

There are 0 best solutions below