mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge with default
This commit is contained in:
commit
7e59c5385e
4
CHANGES
4
CHANGES
@ -20,6 +20,8 @@ Incompatible changes
|
|||||||
templates directory.
|
templates directory.
|
||||||
* Custom domains should implement the new `Domain.resolve_any_xref`
|
* Custom domains should implement the new `Domain.resolve_any_xref`
|
||||||
method to make the `any` role work properly.
|
method to make the `any` role work properly.
|
||||||
|
* gettext builder: disable extracting/apply 'index' node by default. Please set
|
||||||
|
'index' to :confval:`gettext_enables` to enable extracting index entries.
|
||||||
|
|
||||||
Features added
|
Features added
|
||||||
--------------
|
--------------
|
||||||
@ -87,6 +89,8 @@ Features added
|
|||||||
target. Thanks to Takeshi Komiya.
|
target. Thanks to Takeshi Komiya.
|
||||||
* PR#298: Add new API: :meth:`~sphinx.application.Sphinx.add_latex_package`.
|
* PR#298: Add new API: :meth:`~sphinx.application.Sphinx.add_latex_package`.
|
||||||
Thanks to Takeshi Komiya.
|
Thanks to Takeshi Komiya.
|
||||||
|
* #1344: add :confval:`gettext_enables` to enable extracting 'index' to gettext
|
||||||
|
catalog output / applying translation catalog to generated documentation.
|
||||||
|
|
||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
@ -447,6 +447,16 @@ documentation on :ref:`intl` for details.
|
|||||||
|
|
||||||
.. versionadded:: 1.3
|
.. versionadded:: 1.3
|
||||||
|
|
||||||
|
.. confval:: gettext_enables
|
||||||
|
|
||||||
|
To specify names to enable gettext extracting and translation applying for
|
||||||
|
i18n. You can specify below names:
|
||||||
|
|
||||||
|
:index: index terms
|
||||||
|
|
||||||
|
The default is ``[]``.
|
||||||
|
|
||||||
|
.. versionadded:: 1.3
|
||||||
|
|
||||||
.. _html-options:
|
.. _html-options:
|
||||||
|
|
||||||
|
@ -108,15 +108,16 @@ class I18nBuilder(Builder):
|
|||||||
for node, msg in extract_messages(doctree):
|
for node, msg in extract_messages(doctree):
|
||||||
catalog.add(msg, node)
|
catalog.add(msg, node)
|
||||||
|
|
||||||
# Extract translatable messages from index entries.
|
if 'index' in self.env.config.gettext_enables:
|
||||||
for node, entries in traverse_translatable_index(doctree):
|
# Extract translatable messages from index entries.
|
||||||
for typ, msg, tid, main in entries:
|
for node, entries in traverse_translatable_index(doctree):
|
||||||
for m in split_index_msg(typ, msg):
|
for typ, msg, tid, main in entries:
|
||||||
if typ == 'pair' and m in pairindextypes.values():
|
for m in split_index_msg(typ, msg):
|
||||||
# avoid built-in translated message was incorporated
|
if typ == 'pair' and m in pairindextypes.values():
|
||||||
# in 'sphinx.util.nodes.process_index_entry'
|
# avoid built-in translated message was incorporated
|
||||||
continue
|
# in 'sphinx.util.nodes.process_index_entry'
|
||||||
catalog.add(m, node)
|
continue
|
||||||
|
catalog.add(m, node)
|
||||||
|
|
||||||
|
|
||||||
# determine tzoffset once to remain unaffected by DST change during build
|
# determine tzoffset once to remain unaffected by DST change during build
|
||||||
|
@ -211,6 +211,7 @@ class Config(object):
|
|||||||
gettext_location = (True, 'gettext'),
|
gettext_location = (True, 'gettext'),
|
||||||
gettext_uuid = (True, 'gettext'),
|
gettext_uuid = (True, 'gettext'),
|
||||||
gettext_auto_build = (True, 'env'),
|
gettext_auto_build = (True, 'env'),
|
||||||
|
gettext_enables = ([], 'env'),
|
||||||
|
|
||||||
# XML options
|
# XML options
|
||||||
xml_pretty = (True, 'env'),
|
xml_pretty = (True, 'env'),
|
||||||
|
@ -462,22 +462,23 @@ class Locale(Transform):
|
|||||||
node.children = patch.children
|
node.children = patch.children
|
||||||
node['translated'] = True
|
node['translated'] = True
|
||||||
|
|
||||||
# Extract and translate messages for index entries.
|
if 'index' in env.config.gettext_enables:
|
||||||
for node, entries in traverse_translatable_index(self.document):
|
# Extract and translate messages for index entries.
|
||||||
new_entries = []
|
for node, entries in traverse_translatable_index(self.document):
|
||||||
for type, msg, tid, main in entries:
|
new_entries = []
|
||||||
msg_parts = split_index_msg(type, msg)
|
for type, msg, tid, main in entries:
|
||||||
msgstr_parts = []
|
msg_parts = split_index_msg(type, msg)
|
||||||
for part in msg_parts:
|
msgstr_parts = []
|
||||||
msgstr = catalog.gettext(part)
|
for part in msg_parts:
|
||||||
if not msgstr:
|
msgstr = catalog.gettext(part)
|
||||||
msgstr = part
|
if not msgstr:
|
||||||
msgstr_parts.append(msgstr)
|
msgstr = part
|
||||||
|
msgstr_parts.append(msgstr)
|
||||||
|
|
||||||
new_entries.append((type, ';'.join(msgstr_parts), tid, main))
|
new_entries.append((type, ';'.join(msgstr_parts), tid, main))
|
||||||
|
|
||||||
node['raw_entries'] = entries
|
node['raw_entries'] = entries
|
||||||
node['entries'] = new_entries
|
node['entries'] = new_entries
|
||||||
|
|
||||||
|
|
||||||
class RemoveTranslatableInline(Transform):
|
class RemoveTranslatableInline(Transform):
|
||||||
|
@ -6,3 +6,4 @@ keep_warnings = True
|
|||||||
templates_path = ['_templates']
|
templates_path = ['_templates']
|
||||||
html_additional_pages = {'index': 'index.html'}
|
html_additional_pages = {'index': 'index.html'}
|
||||||
release = version = '2013.120'
|
release = version = '2013.120'
|
||||||
|
gettext_enables = ['index']
|
||||||
|
@ -113,6 +113,38 @@ def test_gettext_index_entries(app, status, warning):
|
|||||||
"Exception",
|
"Exception",
|
||||||
"Statement",
|
"Statement",
|
||||||
"Builtin",
|
"Builtin",
|
||||||
|
]
|
||||||
|
for expect in expected_msgids:
|
||||||
|
assert expect in msgids
|
||||||
|
msgids.remove(expect)
|
||||||
|
|
||||||
|
# unexpected msgid existent
|
||||||
|
assert msgids == []
|
||||||
|
|
||||||
|
|
||||||
|
@with_app('gettext', testroot='intl',
|
||||||
|
confoverrides={'gettext_compact': False, 'gettext_enables': []})
|
||||||
|
def test_gettext_disable_index_entries(app, status, warning):
|
||||||
|
# regression test for #976
|
||||||
|
app.builder.build(['index_entries'])
|
||||||
|
|
||||||
|
_msgid_getter = re.compile(r'msgid "(.*)"').search
|
||||||
|
|
||||||
|
def msgid_getter(msgid):
|
||||||
|
m = _msgid_getter(msgid)
|
||||||
|
if m:
|
||||||
|
return m.groups()[0]
|
||||||
|
return None
|
||||||
|
|
||||||
|
pot = (app.outdir / 'index_entries.pot').text(encoding='utf-8')
|
||||||
|
msgids = [_f for _f in map(msgid_getter, pot.splitlines()) if _f]
|
||||||
|
|
||||||
|
expected_msgids = [
|
||||||
|
"i18n with index entries",
|
||||||
|
"index target section",
|
||||||
|
"this is :index:`Newsletter` target paragraph.",
|
||||||
|
"various index entries",
|
||||||
|
"That's all.",
|
||||||
]
|
]
|
||||||
for expect in expected_msgids:
|
for expect in expected_msgids:
|
||||||
assert expect in msgids
|
assert expect in msgids
|
||||||
|
@ -98,5 +98,6 @@ def test_latex_add_latex_package(app, status, warning):
|
|||||||
app.add_latex_package('foo')
|
app.add_latex_package('foo')
|
||||||
app.add_latex_package('bar', 'baz')
|
app.add_latex_package('bar', 'baz')
|
||||||
app.builder.build_all()
|
app.builder.build_all()
|
||||||
assert '\\usepackage{foo}' in (app.outdir / 'SphinxTests.tex').text()
|
result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8')
|
||||||
assert '\\usepackage[baz]{bar}' in (app.outdir / 'SphinxTests.tex').text()
|
assert '\\usepackage{foo}' in result
|
||||||
|
assert '\\usepackage[baz]{bar}' in result
|
||||||
|
Loading…
Reference in New Issue
Block a user