diff options
| author | shimizukawa <shimizukawa@gmail.com> | 2012-11-22 11:43:09 +0900 |
|---|---|---|
| committer | shimizukawa <shimizukawa@gmail.com> | 2012-11-22 11:43:09 +0900 |
| commit | aaef5e456593dbf9386557c47fbaad2052d00864 (patch) | |
| tree | 2593279dea00db08acce67f819301425ba0ba336 | |
| parent | e26f6807079e2b2e9f30a47425977489ca661087 (diff) | |
| download | sphinx-aaef5e456593dbf9386557c47fbaad2052d00864.tar.gz | |
fixed #955: footnote i18n translation cause KeyError and 'Only update text nodes in translation' change at b7b808e46851 break translation.
| -rw-r--r-- | sphinx/environment.py | 19 | ||||
| -rw-r--r-- | tests/root/contents.txt | 1 | ||||
| -rw-r--r-- | tests/root/i18n_footnote.po | 30 | ||||
| -rw-r--r-- | tests/root/i18n_footnote.txt | 10 | ||||
| -rw-r--r-- | tests/test_intl.py | 25 |
5 files changed, 79 insertions, 6 deletions
diff --git a/sphinx/environment.py b/sphinx/environment.py index bfad00f4..9e971ed3 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -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): - child.parent = node - node.children[i] = child + 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 = patch.children class SphinxStandaloneReader(standalone.Reader): diff --git a/tests/root/contents.txt b/tests/root/contents.txt index ad246cb7..3ba41eed 100644 --- a/tests/root/contents.txt +++ b/tests/root/contents.txt @@ -28,6 +28,7 @@ Contents: extensions versioning/index only + i18n_footnote Python <http://python.org/> diff --git a/tests/root/i18n_footnote.po b/tests/root/i18n_footnote.po new file mode 100644 index 00000000..b7f2b584 --- /dev/null +++ b/tests/root/i18n_footnote.po @@ -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." + diff --git a/tests/root/i18n_footnote.txt b/tests/root/i18n_footnote.txt new file mode 100644 index 00000000..3a1097af --- /dev/null +++ b/tests/root/i18n_footnote.txt @@ -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. diff --git a/tests/test_intl.py b/tests/test_intl.py index d1e28002..01005166 100644 --- a/tests/test_intl.py +++ b/tests/test_intl.py @@ -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 |
