mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
refs #1235: i18n: 'doctest-block' and 'raw' node can be translated if gettext_additional_targets
has that string.
This commit is contained in:
parent
c53fa4b369
commit
0ad1c154c0
8
CHANGES
8
CHANGES
@ -23,8 +23,12 @@ Features added
|
|||||||
nav-item-0, 1, 2...).
|
nav-item-0, 1, 2...).
|
||||||
* New option `sphinx-quickstart --use-make-mode` for generating Makefile that
|
* New option `sphinx-quickstart --use-make-mode` for generating Makefile that
|
||||||
use sphinx-build make-mode.
|
use sphinx-build make-mode.
|
||||||
* #1235: i18n: 'literal-block' node can be translated if 'literal-block'
|
* #1235: i18n: several node can be translated if it is set to
|
||||||
is set to `gettext_additional_targets`.
|
`gettext_additional_targets` in conf.py. Supported nodes are:
|
||||||
|
|
||||||
|
- 'literal-block'
|
||||||
|
- 'doctest-block'
|
||||||
|
- 'raw'
|
||||||
|
|
||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
@ -495,6 +495,8 @@ documentation on :ref:`intl` for details.
|
|||||||
|
|
||||||
:index: index terms
|
:index: index terms
|
||||||
:literal-block: literal blocks: ``::`` and ``code-block``.
|
:literal-block: literal blocks: ``::`` and ``code-block``.
|
||||||
|
:doctest-block: doctest block
|
||||||
|
:raw: raw content
|
||||||
|
|
||||||
The default is ``[]``.
|
The default is ``[]``.
|
||||||
|
|
||||||
|
@ -161,6 +161,8 @@ class CitationReferences(Transform):
|
|||||||
|
|
||||||
TRANSLATABLE_NODES = {
|
TRANSLATABLE_NODES = {
|
||||||
'literal-block': nodes.literal_block,
|
'literal-block': nodes.literal_block,
|
||||||
|
'doctest-block': nodes.doctest_block,
|
||||||
|
'raw': nodes.raw,
|
||||||
}
|
}
|
||||||
class ExtraTranslatableNodes(Transform):
|
class ExtraTranslatableNodes(Transform):
|
||||||
"""
|
"""
|
||||||
|
@ -75,6 +75,8 @@ IGNORED_NODES = (
|
|||||||
)
|
)
|
||||||
LITERAL_TYPE_NODES = (
|
LITERAL_TYPE_NODES = (
|
||||||
nodes.literal_block,
|
nodes.literal_block,
|
||||||
|
nodes.doctest_block,
|
||||||
|
nodes.raw,
|
||||||
)
|
)
|
||||||
def extract_messages(doctree):
|
def extract_messages(doctree):
|
||||||
"""Extract translatable messages from a document tree."""
|
"""Extract translatable messages from a document tree."""
|
||||||
@ -92,6 +94,8 @@ def extract_messages(doctree):
|
|||||||
|
|
||||||
if isinstance(node, LITERAL_TYPE_NODES):
|
if isinstance(node, LITERAL_TYPE_NODES):
|
||||||
msg = node.rawsource
|
msg = node.rawsource
|
||||||
|
if not msg:
|
||||||
|
msg = node.astext()
|
||||||
else:
|
else:
|
||||||
msg = node.rawsource.replace('\n', ' ').strip()
|
msg = node.rawsource.replace('\n', ' ').strip()
|
||||||
|
|
||||||
|
@ -21,3 +21,4 @@ CONTENTS
|
|||||||
glossary_terms_inconsistency
|
glossary_terms_inconsistency
|
||||||
versionchange
|
versionchange
|
||||||
docfields
|
docfields
|
||||||
|
raw
|
||||||
|
@ -65,3 +65,22 @@ msgstr ""
|
|||||||
"{\n"
|
"{\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}"
|
"}"
|
||||||
|
|
||||||
|
msgid "doctest blocks"
|
||||||
|
msgstr "DOCTEST-BLOCKS"
|
||||||
|
|
||||||
|
msgid ""
|
||||||
|
">>> import sys # sys importing\n"
|
||||||
|
">>> def main(): # define main function\n"
|
||||||
|
"... sys.stdout.write('hello') # call write method of stdout object\n"
|
||||||
|
">>>\n"
|
||||||
|
">>> if __name__ == '__main__': # if run this py file as python script\n"
|
||||||
|
"... main() # call main"
|
||||||
|
msgstr ""
|
||||||
|
">>> import sys # SYS IMPORTING\n"
|
||||||
|
">>> def main(): # DEFINE MAIN FUNCTION\n"
|
||||||
|
"... sys.stdout.write('hello') # CALL WRITE METHOD OF STDOUT OBJECT\n"
|
||||||
|
">>>\n"
|
||||||
|
">>> if __name__ == '__main__': # IF RUN THIS PY FILE AS PYTHON SCRIPT\n"
|
||||||
|
"... main() # CALL MAIN"
|
||||||
|
|
||||||
|
@ -39,3 +39,16 @@ code blocks
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
doctest blocks
|
||||||
|
==============
|
||||||
|
|
||||||
|
.. highlight:: python
|
||||||
|
|
||||||
|
>>> import sys # sys importing
|
||||||
|
>>> def main(): # define main function
|
||||||
|
... sys.stdout.write('hello') # call write method of stdout object
|
||||||
|
>>>
|
||||||
|
>>> if __name__ == '__main__': # if run this py file as python script
|
||||||
|
... main() # call main
|
||||||
|
|
||||||
|
21
tests/roots/test-intl/raw.po
Normal file
21
tests/roots/test-intl/raw.po
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# SOME DESCRIPTIVE TITLE.
|
||||||
|
# Copyright (C) 2015, dev
|
||||||
|
# This file is distributed under the same license as the 1235 package.
|
||||||
|
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||||
|
#
|
||||||
|
#, fuzzy
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: 1235 1.0\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2015-02-22 15:22+0900\n"
|
||||||
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
|
||||||
|
msgid "<iframe src=\"http://sphinx-doc.org\"></iframe>"
|
||||||
|
msgstr "<iframe src=\"HTTP://SPHINX-DOC.ORG\"></iframe>"
|
||||||
|
|
8
tests/roots/test-intl/raw.txt
Normal file
8
tests/roots/test-intl/raw.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
===
|
||||||
|
Raw
|
||||||
|
===
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<iframe src="http://sphinx-doc.org"></iframe>
|
||||||
|
|
@ -628,6 +628,7 @@ def test_xml_builder(app, status, warning):
|
|||||||
def test_additional_targets_should_not_be_translated(app, status, warning):
|
def test_additional_targets_should_not_be_translated(app, status, warning):
|
||||||
app.builder.build_all()
|
app.builder.build_all()
|
||||||
|
|
||||||
|
## literalblock.txt
|
||||||
result = (app.outdir / 'literalblock.html').text(encoding='utf-8')
|
result = (app.outdir / 'literalblock.html').text(encoding='utf-8')
|
||||||
|
|
||||||
# title should be translated
|
# title should be translated
|
||||||
@ -646,17 +647,35 @@ def test_additional_targets_should_not_be_translated(app, status, warning):
|
|||||||
expected_expr = """<span class="cp">#include <stdio.h></span>"""
|
expected_expr = """<span class="cp">#include <stdio.h></span>"""
|
||||||
yield assert_equal, len(re.findall(expected_expr, result)), 1, (expected_expr, result)
|
yield assert_equal, len(re.findall(expected_expr, result)), 1, (expected_expr, result)
|
||||||
|
|
||||||
|
# doctest block should not be translated but be highlighted
|
||||||
|
expected_expr = (
|
||||||
|
"""<span class="gp">>>> </span>"""
|
||||||
|
"""<span class="kn">import</span> <span class="nn">sys</span> """
|
||||||
|
"""<span class="c"># sys importing</span>""")
|
||||||
|
yield assert_equal, len(re.findall(expected_expr, result)), 1, (expected_expr, result)
|
||||||
|
|
||||||
|
## raw.txt
|
||||||
|
|
||||||
|
result = (app.outdir / 'raw.html').text(encoding='utf-8')
|
||||||
|
|
||||||
|
# raw block should not be translated
|
||||||
|
expected_expr = """<iframe src="http://sphinx-doc.org"></iframe></div>"""
|
||||||
|
yield assert_equal, len(re.findall(expected_expr, result)), 1, (expected_expr, result)
|
||||||
|
|
||||||
|
|
||||||
@gen_with_intl_app('html', freshenv=True,
|
@gen_with_intl_app('html', freshenv=True,
|
||||||
confoverrides={
|
confoverrides={
|
||||||
'gettext_additional_targets': [
|
'gettext_additional_targets': [
|
||||||
'index',
|
'index',
|
||||||
'literal-block',
|
'literal-block',
|
||||||
|
'doctest-block',
|
||||||
|
'raw',
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
def test_additional_targets_should_be_translated(app, status, warning):
|
def test_additional_targets_should_be_translated(app, status, warning):
|
||||||
app.builder.build_all()
|
app.builder.build_all()
|
||||||
|
|
||||||
|
## literalblock.txt
|
||||||
result = (app.outdir / 'literalblock.html').text(encoding='utf-8')
|
result = (app.outdir / 'literalblock.html').text(encoding='utf-8')
|
||||||
|
|
||||||
# title should be translated
|
# title should be translated
|
||||||
@ -675,3 +694,17 @@ def test_additional_targets_should_be_translated(app, status, warning):
|
|||||||
expected_expr = """<span class="cp">#include <STDIO.H></span>"""
|
expected_expr = """<span class="cp">#include <STDIO.H></span>"""
|
||||||
yield assert_equal, len(re.findall(expected_expr, result)), 1, (expected_expr, result)
|
yield assert_equal, len(re.findall(expected_expr, result)), 1, (expected_expr, result)
|
||||||
|
|
||||||
|
# doctest block should not be translated but be highlighted
|
||||||
|
expected_expr = (
|
||||||
|
"""<span class="gp">>>> </span>"""
|
||||||
|
"""<span class="kn">import</span> <span class="nn">sys</span> """
|
||||||
|
"""<span class="c"># SYS IMPORTING</span>""")
|
||||||
|
yield assert_equal, len(re.findall(expected_expr, result)), 1, (expected_expr, result)
|
||||||
|
|
||||||
|
## raw.txt
|
||||||
|
|
||||||
|
result = (app.outdir / 'raw.html').text(encoding='utf-8')
|
||||||
|
|
||||||
|
# raw block should be translated
|
||||||
|
expected_expr = """<iframe src="HTTP://SPHINX-DOC.ORG"></iframe></div>"""
|
||||||
|
yield assert_equal, len(re.findall(expected_expr, result)), 1, (expected_expr, result)
|
||||||
|
Loading…
Reference in New Issue
Block a user