mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
fixed #955: footnote i18n translation cause KeyError and 'Only update text nodes in translation' change at b7b808e46851 break translation.
This commit is contained in:
parent
4e715ff0bf
commit
30c3fff6d7
@ -226,11 +226,20 @@ class Locale(Transform):
|
||||
if not isinstance(patch, nodes.paragraph):
|
||||
continue # skip for now
|
||||
|
||||
# copy text children
|
||||
for i, child in enumerate(patch.children):
|
||||
if isinstance(child, nodes.Text):
|
||||
footnote_refs = [r for r in node.children
|
||||
if isinstance(r, nodes.footnote_reference)
|
||||
and r.get('auto') == 1]
|
||||
for i, child in enumerate(patch.children): # update leaves
|
||||
if isinstance(child, nodes.footnote_reference):
|
||||
# use original 'footnote_reference' object.
|
||||
# this object already registered in self.document.autofootnote_refs
|
||||
patch.children[i] = footnote_refs.pop(0)
|
||||
# Some duplicated footnote_reference in msgstr cause
|
||||
# IndexError by .pop(0). That is invalid msgstr.
|
||||
|
||||
for child in patch.children: # update leaves
|
||||
child.parent = node
|
||||
node.children[i] = child
|
||||
node.children = patch.children
|
||||
|
||||
|
||||
class SphinxStandaloneReader(standalone.Reader):
|
||||
|
@ -28,6 +28,7 @@ Contents:
|
||||
extensions
|
||||
versioning/index
|
||||
only
|
||||
i18n_footnote
|
||||
|
||||
Python <http://python.org/>
|
||||
|
||||
|
30
tests/root/i18n_footnote.po
Normal file
30
tests/root/i18n_footnote.po
Normal file
@ -0,0 +1,30 @@
|
||||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) 2012, foof
|
||||
# This file is distributed under the same license as the foo package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: sphinx 1.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2012-11-22 08:28\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 "i18n with Footnote"
|
||||
msgstr "I18N WITH FOOTNOTE"
|
||||
|
||||
msgid "Contents [#]_ for `i18n with Footnote`_ [ref]_"
|
||||
msgstr "`I18N WITH FOOTNOTE`_ INCLUDE THIS CONTENTS [ref]_ [#]_"
|
||||
|
||||
msgid "This is a auto numbered footnote."
|
||||
msgstr "THIS IS A AUTO NUMBERED FOOTNOTE."
|
||||
|
||||
msgid "This is a named footnote."
|
||||
msgstr "THIS IS A NAMED FOOTNOTE."
|
||||
|
10
tests/root/i18n_footnote.txt
Normal file
10
tests/root/i18n_footnote.txt
Normal file
@ -0,0 +1,10 @@
|
||||
:tocdepth: 2
|
||||
|
||||
i18n with Footnote
|
||||
==================
|
||||
.. #955 cant-build-html-with-footnotes-when-using
|
||||
|
||||
Contents [#]_ for `i18n with Footnote`_ [ref]_
|
||||
|
||||
.. [#] This is a auto numbered footnote.
|
||||
.. [ref] This is a named footnote.
|
@ -19,7 +19,7 @@ from util import SkipTest
|
||||
def setup_module():
|
||||
(test_root / 'xx' / 'LC_MESSAGES').makedirs()
|
||||
# Compile all required catalogs into binary format (*.mo).
|
||||
for catalog in 'bom', 'subdir':
|
||||
for catalog in 'bom', 'subdir', 'i18n_footnote':
|
||||
try:
|
||||
p = Popen(['msgfmt', test_root / '%s.po' % catalog, '-o',
|
||||
test_root / 'xx' / 'LC_MESSAGES' / '%s.mo' % catalog],
|
||||
@ -63,3 +63,26 @@ def test_subdir(app):
|
||||
app.builder.build(['subdir/includes'])
|
||||
result = (app.outdir / 'subdir' / 'includes.txt').text(encoding='utf-8')
|
||||
assert result.startswith(u"\ntranslation\n***********\n\n")
|
||||
|
||||
|
||||
@with_app(buildername='html',
|
||||
confoverrides={'language': 'xx', 'locale_dirs': ['.']})
|
||||
def test_i18n_footnote_break_refid(app):
|
||||
"""test for #955 cant-build-html-with-footnotes-when-using"""
|
||||
app.builder.build(['i18n_footnote'])
|
||||
result = (app.outdir / 'i18n_footnote.html').text(encoding='utf-8')
|
||||
# expect no error by build
|
||||
|
||||
|
||||
@with_app(buildername='text',
|
||||
confoverrides={'language': 'xx', 'locale_dirs': ['.']})
|
||||
def test_i18n_footnote_regression(app):
|
||||
"""regression test for fix #955"""
|
||||
app.builder.build(['i18n_footnote'])
|
||||
result = (app.outdir / 'i18n_footnote.txt').text(encoding='utf-8')
|
||||
expect = (u"\nI18N WITH FOOTNOTE"
|
||||
u"\n******************\n" # underline matches new translation
|
||||
u"\nI18N WITH FOOTNOTE INCLUDE THIS CONTENTS [ref] [1]\n"
|
||||
u"\n[1] THIS IS A AUTO NUMBERED FOOTNOTE.\n"
|
||||
u"\n[ref] THIS IS A NAMED FOOTNOTE.\n")
|
||||
assert result == expect
|
||||
|
Loading…
Reference in New Issue
Block a user