зеркало из https://github.com/microsoft/nni.git
Patch of translation for sphinx 4.5 (#4708)
This commit is contained in:
Родитель
84d3746f1b
Коммит
751bb6fde0
|
@ -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
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
"""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',
|
||||
]
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
"""
|
||||
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)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче