diff --git a/CHANGES b/CHANGES index 3311e571e..4ddb209f2 100644 --- a/CHANGES +++ b/CHANGES @@ -50,6 +50,7 @@ Bugs fixed * #1725: On py2 environment, doctest with using non-ASCII characters causes ``'ascii' codec can't decode byte`` exception. * #1540: Fix RuntimeError with circular referenced toctree +* #1983: i18n translation feature breaks references which uses section name. Release 1.3.1 (released Mar 17, 2015) diff --git a/sphinx/transforms.py b/sphinx/transforms.py index 3d12eb230..afb91d935 100644 --- a/sphinx/transforms.py +++ b/sphinx/transforms.py @@ -277,8 +277,10 @@ class Locale(Transform): # document nameids mapping with new name. names = section_node.setdefault('names', []) names.append(new_name) - if old_name in names: - names.remove(old_name) + # Original section name (reference target name) should be kept to refer + # from other nodes which is still not translated or uses explicit target + # name like "`text to display `_".. + # So, `old_name` is still exist in `names`. _id = self.document.nameids.get(old_name, None) explicit = self.document.nametypes.get(old_name, None) diff --git a/tests/roots/test-intl/contents.txt b/tests/roots/test-intl/contents.txt index 418b3022c..8882137f3 100644 --- a/tests/roots/test-intl/contents.txt +++ b/tests/roots/test-intl/contents.txt @@ -22,3 +22,4 @@ CONTENTS versionchange docfields raw + refs diff --git a/tests/roots/test-intl/refs.po b/tests/roots/test-intl/refs.po new file mode 100644 index 000000000..510a5a7fc --- /dev/null +++ b/tests/roots/test-intl/refs.po @@ -0,0 +1,85 @@ +# +msgid "" +msgstr "" +"Project-Id-Version: 1191 1.3\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-08-08 15:31+0900\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "Translation Tips" +msgstr "X TIPS" + +msgid "A-1. Here's how you can `download Sphinx`_." +msgstr "A-1. HERE'S HOW YOU CAN `download Sphinx`_." + +msgid "A-2. Here's how you can `download Sphinx`_." +msgstr "A-2. HERE'S HOW YOU CAN `A1 DOWNLOAD SPHINX`_." + +msgid "A-3. Here's how you can `download Sphinx`_." +msgstr "" +"A-3. HERE'S HOW YOU CAN `A3 DOWNLOAD SPHINX `_ AND `A3 DOWNLOAD " +"SPHINX `_." + +msgid "B-1. `Docutils site`_ and `Sphinx site`_." +msgstr "B-1. `Docutils site`_ and `Sphinx site`_." + +msgid "B-2. `Docutils site`_ and `Sphinx site`_." +msgstr "B-2. `B1 DOCUTILS SITE`_ AND `B1 SPHINX SITE`_." + +msgid "B-3. `Docutils site`_ and `Sphinx site`_." +msgstr "B-3. `B2 SPHINX SITE`_ AND `B2 DOCUTILS SITE`_." + +msgid "B-4. `Docutils site`_ and `Sphinx site`_." +msgstr "" +"B-4. `B4 SPHINX SITE `_ AND `B4 DOCUTILS SITE `_." + +msgid "B-5. `Docutils site`_ and `Sphinx site`_." +msgstr "" +"B-5. `B5 SPHINX SITE `_ AND `B5 DOCUTILS SITE `_\" AND `B5 SPHINX SITE `_." + +msgid "C-1. Link to `Translation Tips`_ section." +msgstr "C-1. LINK TO `Translation Tips`_ SECTION." + +msgid "C-2. Link to `Translation Tips`_ section." +msgstr "C-2. LINK TO `X TIPS`_ SECTION." + +msgid "C-3. Link to `Translation Tips`_ section." +msgstr "C-3. LINK TO `X TIPS `_ SECTION." + +msgid "C-4. Link to `Translation Tips`_ section." +msgstr "" +"C-4. LINK TO `X TIPS `_ x `X TIPS `_ " +"SECTION." + +msgid "C-5. Link to `Translation Tips`_ section." +msgstr "" +"C-5. LINK TO `TRANS `_ x `LATION `_ " + +msgid "D-1. Link to `Translation Tips`_ and `Next Section`_ section." +msgstr "D-1. LINK TO `Translation Tips`_ and `Next Section`_ SECTION." + +msgid "D-2. Link to `Translation Tips`_ and `Next Section`_ section." +msgstr "D-2. LINK TO `X TIPS`_ AND `N SECTION`_ SECTION." + +msgid "D-3. Link to `Translation Tips`_ and `Next Section`_ section." +msgstr "D-3. LINK TO `N SECTION`_ AND `X TIPS`_ SECTION." + +msgid "D-4. Link to `Translation Tips`_ and `Next Section`_ section." +msgstr "" +"D-4. LINK TO `N SECTION `_ AND `X TIPS `_ " +"SECTION." + +msgid "D-5. Link to `Translation Tips`_ and `Next Section`_ section." +msgstr "" +"D-5. LINK TO `Next `_ AND `Tips `_ " + +msgid "Next Section" +msgstr "N SECTION" + diff --git a/tests/roots/test-intl/refs.txt b/tests/roots/test-intl/refs.txt new file mode 100644 index 000000000..b093dbe60 --- /dev/null +++ b/tests/roots/test-intl/refs.txt @@ -0,0 +1,47 @@ +References +=========== + +Translation Tips +----------------- + +.. _download Sphinx: https://pypi.python.org/pypi/sphinx +.. _Docutils site: http://docutils.sourceforge.net/ +.. _Sphinx site: http://sphinx-doc.org/ + + +A-1. Here's how you can `download Sphinx`_. + +A-2. Here's how you can `download Sphinx`_. + +A-3. Here's how you can `download Sphinx`_. + +B-1. `Docutils site`_ and `Sphinx site`_. + +B-2. `Docutils site`_ and `Sphinx site`_. + +B-3. `Docutils site`_ and `Sphinx site`_. + +B-4. `Docutils site`_ and `Sphinx site`_. + +C-1. Link to `Translation Tips`_ section. + +C-2. Link to `Translation Tips`_ section. + +C-3. Link to `Translation Tips`_ section. + +C-4. Link to `Translation Tips`_ section. + +C-5. Link to `Translation Tips`_ section. + +D-1. Link to `Translation Tips`_ and `Next Section`_ section. + +D-2. Link to `Translation Tips`_ and `Next Section`_ section. + +D-3. Link to `Translation Tips`_ and `Next Section`_ section. + +D-4. Link to `Translation Tips`_ and `Next Section`_ section. + +D-5. Link to `Translation Tips`_ and `Next Section`_ section. + +Next Section +------------- diff --git a/tests/test_intl.py b/tests/test_intl.py index 965fdf187..dabb2a3f5 100644 --- a/tests/test_intl.py +++ b/tests/test_intl.py @@ -751,3 +751,11 @@ def test_additional_targets_should_be_translated(app, status, warning): expected_expr = """IMG -> I18N""" yield assert_count(expected_expr, result, 1) + +@gen_with_intl_app('text', freshenv=True) +def test_references(app, status, warning): + app.builder.build_specific([app.srcdir / 'refs.txt']) + + warnings = warning.getvalue().replace(os.sep, '/') + warning_expr = u'refs.txt:\\d+: ERROR: Unknown target name:' + yield assert_count(warning_expr, warnings, 0)