如果存在超链接,如何翻译Sphinx的'parsed-literal'指令的内容?

问题描述 投票:0回答:1

问题描述

最近,我尝试使用

.po
构建器生成的 gettext
gettext
文件来构建 CMake 文档。但是,我想知道如果存在超链接,如何翻译
parsed-literal
指令的内容?

以这部分为例。通常,我们应该像下面这样翻译

.rst
中的超链接:(对吗?)

# Source (msgid)
`Build a Project`_

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

但是,在运行

sphinx-build
使用此翻译构建 HTML 文档后,超链接被破坏。并且有一条警告消息:

/home/hwhsu1231/Repo/testing/cmake-v3.28.4/Help/manual/cmake.1.rst:11:警告:翻译消息中的引用不一致。原:['

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
_'], 翻译: []

发生什么事了?怎么解决?

如何重现

  1. 下载演示项目:

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

  2. 按顺序运行以下命令:

    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
    

环境信息

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

其他背景

“如何重现”完整日志如下:

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$ 

与官方文档(cmake.1.html)相比,以下截图是我构建的。正如我们所看到的,超链接已损坏。

Preview the cmake.1.html built with translations

cmake python-sphinx gettext restructuredtext
1个回答
0
投票

在普通的 Docutils 中,带有嵌入别名的翻译后的引用在解析的文字块中工作得很好。

根据 mzjn 链接的错误报告,原因似乎是“parsed-literal”和“gettext”翻译功能的干扰。 翻译后的“parsed-literal”并未真正解析,无法创建名为建置专案的新目标(参见嵌入式 URI 和别名)。

如果在其他地方依赖新建立的目标使用超链接引用,则可能会导致后续错误:

Like here `建置專案`_.

您可以添加显式超链接目标 或对所有翻译使用 anonymous 别名超链接(带有两个尾部下划线)。

© www.soinside.com 2019 - 2024. All rights reserved.