mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
parent
f50091b643
commit
c347b50330
@ -229,6 +229,8 @@ class Locale(Transform):
|
||||
footnote_refs = [r for r in node.children
|
||||
if isinstance(r, nodes.footnote_reference)
|
||||
and r.get('auto') == 1]
|
||||
refs = [r for r in node.children if isinstance(r, nodes.reference)]
|
||||
|
||||
for i, child in enumerate(patch.children): # update leaves
|
||||
if isinstance(child, nodes.footnote_reference) \
|
||||
and child.get('auto') == 1:
|
||||
@ -238,6 +240,18 @@ class Locale(Transform):
|
||||
# Some duplicated footnote_reference in msgstr cause
|
||||
# IndexError by .pop(0). That is invalid msgstr.
|
||||
|
||||
elif isinstance(child, nodes.reference):
|
||||
# reference use original 'refname'.
|
||||
# * reference target ".. _Python: ..." is not translatable.
|
||||
# * section refname is not translatable.
|
||||
# * inline reference "`Python <...>`_" have no 'refname'.
|
||||
if refs and 'refname' in refs[0]:
|
||||
refname = child['refname'] = refs.pop(0)['refname']
|
||||
self.document.refnames.setdefault(
|
||||
refname, []).append(child)
|
||||
# if reference node count is not same before translation
|
||||
# that offen generate unknown link target warning.
|
||||
|
||||
for child in patch.children: # update leaves
|
||||
child.parent = node
|
||||
node.children = patch.children
|
||||
|
@ -29,6 +29,7 @@ Contents:
|
||||
versioning/index
|
||||
only
|
||||
i18n_footnote
|
||||
i18n_external_links
|
||||
|
||||
Python <http://python.org/>
|
||||
|
||||
|
32
tests/root/i18n_external_links.po
Normal file
32
tests/root/i18n_external_links.po
Normal file
@ -0,0 +1,32 @@
|
||||
# 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 external links"
|
||||
msgstr "EXTERNAL LINKS"
|
||||
|
||||
msgid "External link to Python_."
|
||||
msgstr "EXTERNAL LINK TO Python_."
|
||||
|
||||
msgid "Internal link to `i18n with external links`_."
|
||||
msgstr "`EXTERNAL LINKS`_ IS INTERNAL LINK."
|
||||
|
||||
msgid "Inline link by `Sphinx <http://sphinx-doc.org>`_."
|
||||
msgstr "INLINE LINK BY `SPHINX <http://sphinx-doc.org>`_."
|
||||
|
||||
msgid "Unnamed link__."
|
||||
msgstr "UNNAMED LINK__."
|
13
tests/root/i18n_external_links.txt
Normal file
13
tests/root/i18n_external_links.txt
Normal file
@ -0,0 +1,13 @@
|
||||
:tocdepth: 2
|
||||
|
||||
i18n with external links
|
||||
========================
|
||||
.. #1044 external-links-dont-work-in-localized-html
|
||||
|
||||
* External link to Python_.
|
||||
* Internal link to `i18n with external links`_.
|
||||
* Inline link by `Sphinx <http://sphinx-doc.org>`_.
|
||||
* Unnamed link__.
|
||||
|
||||
.. _Python: http://python.org
|
||||
.. __: http://google.com
|
@ -11,6 +11,7 @@
|
||||
"""
|
||||
|
||||
from subprocess import Popen, PIPE
|
||||
import re
|
||||
|
||||
from util import *
|
||||
from util import SkipTest
|
||||
@ -19,7 +20,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', 'i18n_footnote':
|
||||
for catalog in 'bom', 'subdir', 'i18n_footnote', 'i18n_external_links':
|
||||
try:
|
||||
p = Popen(['msgfmt', test_root / '%s.po' % catalog, '-o',
|
||||
test_root / 'xx' / 'LC_MESSAGES' / '%s.mo' % catalog],
|
||||
@ -87,3 +88,43 @@ def test_i18n_footnote_regression(app):
|
||||
u"\n[ref] THIS IS A NAMED FOOTNOTE.\n"
|
||||
u"\n[100] THIS IS A NUMBERED FOOTNOTE.\n")
|
||||
assert result == expect
|
||||
|
||||
|
||||
@with_app(buildername='html',
|
||||
confoverrides={'language': 'xx', 'locale_dirs': ['.']})
|
||||
def test_i18n_keep_external_links(app):
|
||||
"""regression test for #1044"""
|
||||
app.builder.build(['i18n_external_links'])
|
||||
result = (app.outdir / 'i18n_external_links.html').text(encoding='utf-8')
|
||||
|
||||
# external link check
|
||||
expect_line = u"""<li>EXTERNAL LINK TO <a class="reference external" href="http://python.org">Python</a>.</li>"""
|
||||
matched = re.search('^<li>EXTERNAL LINK TO .*$', result, re.M)
|
||||
matched_line = ''
|
||||
if matched:
|
||||
matched_line = matched.group()
|
||||
assert expect_line == matched_line
|
||||
|
||||
# internal link check
|
||||
expect_line = u"""<li><a class="reference internal" href="#i18n-with-external-links">EXTERNAL LINKS</a> IS INTERNAL LINK.</li>"""
|
||||
matched = re.search('^<li><a .* IS INTERNAL LINK.</li>$', result, re.M)
|
||||
matched_line = ''
|
||||
if matched:
|
||||
matched_line = matched.group()
|
||||
assert expect_line == matched_line
|
||||
|
||||
# inline link check
|
||||
expect_line = u"""<li>INLINE LINK BY <a class="reference external" href="http://sphinx-doc.org">SPHINX</a>.</li>"""
|
||||
matched = re.search('^<li>INLINE LINK BY .*$', result, re.M)
|
||||
matched_line = ''
|
||||
if matched:
|
||||
matched_line = matched.group()
|
||||
assert expect_line == matched_line
|
||||
|
||||
# unnamed link check
|
||||
expect_line = u"""<li>UNNAMED <a class="reference external" href="http://google.com">LINK</a>.</li>"""
|
||||
matched = re.search('^<li>UNNAMED .*$', result, re.M)
|
||||
matched_line = ''
|
||||
if matched:
|
||||
matched_line = matched.group()
|
||||
assert expect_line == matched_line
|
||||
|
Loading…
Reference in New Issue
Block a user