Merge with default

This commit is contained in:
tk0miya 2014-09-28 21:56:20 +09:00
commit 7e59c5385e
8 changed files with 76 additions and 25 deletions

View File

@ -20,6 +20,8 @@ Incompatible changes
templates directory.
* Custom domains should implement the new `Domain.resolve_any_xref`
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
--------------
@ -87,6 +89,8 @@ Features added
target. Thanks to Takeshi Komiya.
* PR#298: Add new API: :meth:`~sphinx.application.Sphinx.add_latex_package`.
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
----------

View File

@ -447,6 +447,16 @@ documentation on :ref:`intl` for details.
.. 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:

View File

@ -108,15 +108,16 @@ class I18nBuilder(Builder):
for node, msg in extract_messages(doctree):
catalog.add(msg, node)
# Extract translatable messages from index entries.
for node, entries in traverse_translatable_index(doctree):
for typ, msg, tid, main in entries:
for m in split_index_msg(typ, msg):
if typ == 'pair' and m in pairindextypes.values():
# avoid built-in translated message was incorporated
# in 'sphinx.util.nodes.process_index_entry'
continue
catalog.add(m, node)
if 'index' in self.env.config.gettext_enables:
# Extract translatable messages from index entries.
for node, entries in traverse_translatable_index(doctree):
for typ, msg, tid, main in entries:
for m in split_index_msg(typ, msg):
if typ == 'pair' and m in pairindextypes.values():
# avoid built-in translated message was incorporated
# in 'sphinx.util.nodes.process_index_entry'
continue
catalog.add(m, node)
# determine tzoffset once to remain unaffected by DST change during build

View File

@ -211,6 +211,7 @@ class Config(object):
gettext_location = (True, 'gettext'),
gettext_uuid = (True, 'gettext'),
gettext_auto_build = (True, 'env'),
gettext_enables = ([], 'env'),
# XML options
xml_pretty = (True, 'env'),

View File

@ -462,22 +462,23 @@ class Locale(Transform):
node.children = patch.children
node['translated'] = True
# Extract and translate messages for index entries.
for node, entries in traverse_translatable_index(self.document):
new_entries = []
for type, msg, tid, main in entries:
msg_parts = split_index_msg(type, msg)
msgstr_parts = []
for part in msg_parts:
msgstr = catalog.gettext(part)
if not msgstr:
msgstr = part
msgstr_parts.append(msgstr)
if 'index' in env.config.gettext_enables:
# Extract and translate messages for index entries.
for node, entries in traverse_translatable_index(self.document):
new_entries = []
for type, msg, tid, main in entries:
msg_parts = split_index_msg(type, msg)
msgstr_parts = []
for part in msg_parts:
msgstr = catalog.gettext(part)
if not 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['entries'] = new_entries
node['raw_entries'] = entries
node['entries'] = new_entries
class RemoveTranslatableInline(Transform):

View File

@ -6,3 +6,4 @@ keep_warnings = True
templates_path = ['_templates']
html_additional_pages = {'index': 'index.html'}
release = version = '2013.120'
gettext_enables = ['index']

View File

@ -113,6 +113,38 @@ def test_gettext_index_entries(app, status, warning):
"Exception",
"Statement",
"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:
assert expect in msgids

View File

@ -98,5 +98,6 @@ def test_latex_add_latex_package(app, status, warning):
app.add_latex_package('foo')
app.add_latex_package('bar', 'baz')
app.builder.build_all()
assert '\\usepackage{foo}' in (app.outdir / 'SphinxTests.tex').text()
assert '\\usepackage[baz]{bar}' in (app.outdir / 'SphinxTests.tex').text()
result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8')
assert '\\usepackage{foo}' in result
assert '\\usepackage[baz]{bar}' in result