"git@developer.sourcefind.cn:gaoqiong/migraphx.git" did not exist on "2c779d0b574cde9055b980145504ee9fb0d0ed3a"
Unverified Commit 751bb6fd authored by Yuge Zhang's avatar Yuge Zhang Committed by GitHub
Browse files

Patch of translation for sphinx 4.5 (#4708)

parent 84d3746f
......@@ -10,7 +10,7 @@ pytest
pytest-azurepipelines
pytest-cov
rstcheck
sphinx >= 4.4
sphinx >= 4.5
sphinx-argparse-nni >= 0.4.0
sphinx-gallery
sphinxcontrib-bibtex
......
"""Additional docutils patch to suppress warnings in i18n documentation build."""
from typing import Any
import docutils
from docutils.utils import Reporter
class Patch:
"""
This is actually done in sphinx, but sphinx didn't replace all `get_language` occurrences.
https://github.com/sphinx-doc/sphinx/blob/680417a10df7e5c35c0ff65979bd22906b9a5f1e/sphinx/util/docutils.py#L127
Related issue:
https://github.com/sphinx-doc/sphinx/issues/10179
"""
original = None
def restore(self, *args, **kwargs):
assert self.original is not None
docutils.parsers.rst.languages.get_language = self.original
def patch(self, *args, **kwargs):
from docutils.parsers.rst.languages import get_language
self.original = get_language
def patched_get_language(language_code: str, reporter: Reporter = None) -> Any:
return get_language(language_code)
docutils.parsers.rst.languages.get_language = patched_get_language
def setup(app):
# See life-cycle of sphinx app here:
# https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx-core-events
patch = Patch()
app.connect('env-before-read-docs', patch.patch)
app.connect('env-merge-info', patch.restore)
......@@ -62,7 +62,6 @@ extensions = [
'inplace_translation',
'cardlinkitem',
'codesnippetcard',
'patch_docutils',
'patch_autodoc',
]
......
"""
Fix a troublsome translation in sphinx.
Related PR: https://github.com/sphinx-doc/sphinx/pull/10303
"""
import subprocess
from pathlib import Path
import sphinx
sphinx_path = Path(sphinx.__path__[0]) / 'locale/zh_CN/LC_MESSAGES'
po_content = (sphinx_path / 'sphinx.po').read_text()
po_content = po_content.replace('%s的别名', '%s 的别名')
(sphinx_path / 'sphinx.po').write_text(po_content)
# build po -> mo
subprocess.run(['msgfmt', '-c', str(sphinx_path / 'sphinx.po'), '-o', str(sphinx_path / 'sphinx.mo')], check=True)
......@@ -29,7 +29,11 @@ stages:
displayName: Sphinx sanity check
- script: |
set -e
cd docs
rm -rf build
sudo apt-get install -y gettext
python tools/translation_patch.py
make -e SPHINXOPTS="-W --keep-going -T -q -D language='zh'" html
displayName: Sphinx sanity check (Chinese)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment