mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Backed out changeset cfe9e2d11003 refs #1265
This commit is contained in:
parent
603a75d8d3
commit
313559116d
19
CHANGES
19
CHANGES
@ -1,22 +1,3 @@
|
||||
Release 1.2 (in development)
|
||||
============================
|
||||
|
||||
Features added
|
||||
--------------
|
||||
|
||||
* i18n: gettext translates label target name.
|
||||
|
||||
Incompatible changes
|
||||
--------------------
|
||||
|
||||
|
||||
Bugs fixed
|
||||
----------
|
||||
|
||||
* #1265: Fix i18n: crash when using a indirect target and translating a target
|
||||
section name.
|
||||
|
||||
|
||||
Release 1.2 beta3 (released Oct 3, 2013)
|
||||
========================================
|
||||
|
||||
|
@ -18,11 +18,7 @@ from uuid import uuid4
|
||||
|
||||
from sphinx.builders import Builder
|
||||
from sphinx.util import split_index_msg
|
||||
from sphinx.util.nodes import (
|
||||
extract_messages,
|
||||
traverse_translatable_target,
|
||||
traverse_translatable_index,
|
||||
)
|
||||
from sphinx.util.nodes import extract_messages, traverse_translatable_index
|
||||
from sphinx.util.osutil import safe_relpath, ensuredir, find_catalog, SEP
|
||||
from sphinx.util.console import darkgreen, purple, bold
|
||||
from sphinx.locale import pairindextypes
|
||||
@ -101,9 +97,6 @@ class I18nBuilder(Builder):
|
||||
for node, msg in extract_messages(doctree):
|
||||
catalog.add(msg, node)
|
||||
|
||||
for node, msg in traverse_translatable_target(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:
|
||||
|
@ -20,11 +20,7 @@ from docutils.transforms.parts import ContentsFilter
|
||||
from sphinx import addnodes
|
||||
from sphinx.locale import _, init as init_locale
|
||||
from sphinx.util import split_index_msg
|
||||
from sphinx.util.nodes import (
|
||||
traverse_translatable_target,
|
||||
traverse_translatable_index,
|
||||
extract_messages,
|
||||
)
|
||||
from sphinx.util.nodes import traverse_translatable_index, extract_messages
|
||||
from sphinx.util.osutil import ustrftime, find_catalog
|
||||
from sphinx.util.compat import docutils_version
|
||||
from sphinx.util.pycompat import all
|
||||
@ -182,34 +178,6 @@ class Locale(Transform):
|
||||
parser = RSTParser()
|
||||
|
||||
#phase1: replace reference ids with translated names
|
||||
for node, msg in traverse_translatable_target(self.document):
|
||||
msgstr = catalog.gettext(msg)
|
||||
# XXX add marker to untranslated parts
|
||||
if not msgstr or msgstr == msg or not msgstr.strip():
|
||||
# as-of-yet untranslated
|
||||
continue
|
||||
|
||||
patch = new_document(source, settings)
|
||||
CustomLocaleReporter(node.source, node.line).set_reporter(patch)
|
||||
parser.parse(msgstr, patch)
|
||||
patch = patch[0]
|
||||
|
||||
# XXX doctest and other block markup
|
||||
if not isinstance(patch, nodes.paragraph):
|
||||
continue # skip for now
|
||||
|
||||
old_name = msg
|
||||
new_name = nodes.fully_normalize_name(patch.astext())
|
||||
|
||||
if old_name in self.document.nameids:
|
||||
self.document.nameids[new_name] = (
|
||||
self.document.nameids[old_name])
|
||||
self.document.nametypes[new_name] = (
|
||||
self.document.nametypes[old_name])
|
||||
self.document.refnames[new_name] = (
|
||||
self.document.refnames[old_name])
|
||||
|
||||
#phase2: replace reference ids with translated names
|
||||
for node, msg in extract_messages(self.document):
|
||||
msgstr = catalog.gettext(msg)
|
||||
# XXX add marker to untranslated parts
|
||||
@ -266,9 +234,9 @@ class Locale(Transform):
|
||||
# _id was not duplicated.
|
||||
# remove old_name entry from document ids database
|
||||
# to reuse original _id.
|
||||
self.document.nameids.pop(old_name, None) #supplemental
|
||||
self.document.nametypes.pop(old_name, None) #supplemental
|
||||
self.document.ids.pop(_id, None) # must remove
|
||||
self.document.nameids.pop(old_name, None)
|
||||
self.document.nametypes.pop(old_name, None)
|
||||
self.document.ids.pop(_id, None)
|
||||
|
||||
# re-entry with new named section node.
|
||||
self.document.note_implicit_target(
|
||||
@ -310,7 +278,7 @@ class Locale(Transform):
|
||||
node['translated'] = True
|
||||
|
||||
|
||||
#phase3: translation
|
||||
#phase2: translation
|
||||
for node, msg in extract_messages(self.document):
|
||||
if node.get('translated', False):
|
||||
continue
|
||||
@ -454,7 +422,7 @@ class Locale(Transform):
|
||||
node.children = patch.children
|
||||
node['translated'] = True
|
||||
|
||||
#phase4: Extract and translate messages for index entries.
|
||||
# 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:
|
||||
|
@ -77,13 +77,6 @@ def extract_messages(doctree):
|
||||
yield node, msg
|
||||
|
||||
|
||||
def traverse_translatable_target(doctree):
|
||||
"""Extract translatable target from a document tree."""
|
||||
for node in doctree.traverse(nodes.target):
|
||||
if 'names' in node and node['names']:
|
||||
yield node, node['names'][0]
|
||||
|
||||
|
||||
def traverse_translatable_index(doctree):
|
||||
"""Traverse translatable index node from a document tree."""
|
||||
def is_block_index(node):
|
||||
|
@ -31,10 +31,10 @@ msgstr "X EXPLICIT-TARGET"
|
||||
|
||||
msgid ""
|
||||
":ref:`explicit-target` point to ``explicit-target`` and `explicit-target`_"
|
||||
" point to ``explicit-target`` too."
|
||||
" point to duplicated id like ``id1``."
|
||||
msgstr ""
|
||||
":ref:`explicit-target` POINT TO ``explicit-target`` AND `X EXPLICIT-TARGET`_"
|
||||
" POINT TO ``explicit-target`` TOO."
|
||||
" POINT TO DUPLICATED ID LIKE ``id1``."
|
||||
|
||||
msgid "implicit section name"
|
||||
msgstr "X IMPLICIT SECTION NAME"
|
||||
@ -53,21 +53,14 @@ msgstr ""
|
||||
msgid "label bridged target section"
|
||||
msgstr "X LABEL BRIDGED TARGET SECTION"
|
||||
|
||||
msgid "`bridge label`_ is also translatable and linked to translated section title."
|
||||
msgstr "X `Y BRIDGE LABEL`_ IS ALSO TRANSLATABLE AND LINKED TO TRANSLATED SECTION TITLE."
|
||||
msgid "`bridge label`_ is not translatable but linked to translated section title."
|
||||
msgstr "X `bridge label`_ IS NOT TRANSLATABLE BUT LINKED TO TRANSLATED SECTION TITLE."
|
||||
|
||||
msgid ""
|
||||
"`bridge label2`_ point to ``section and label`` and `bridge label`_ point to "
|
||||
"``label bridged target section``. The second appeared `bridge label2`_ point "
|
||||
"to correct target."
|
||||
msgstr ""
|
||||
"X `Y BRIDGE LABEL`_ POINT TO ``LABEL BRIDGED TARGET SECTION`` AND "
|
||||
"`Z BRIDGE LABEL2`_ POINT TO ``SECTION AND LABEL``. THE SECOND APPEARED "
|
||||
"`Z BRIDGE LABEL2`_ POINT TO CORRECT TARGET."
|
||||
|
||||
msgid "bridge label"
|
||||
msgstr "Y BRIDGE LABEL"
|
||||
|
||||
msgid "bridge label2"
|
||||
msgstr "Z BRIDGE LABEL2"
|
||||
|
||||
"X `bridge label`_ POINT TO ``LABEL BRIDGED TARGET SECTION`` AND "
|
||||
"`bridge label2`_ POINT TO ``SECTION AND LABEL``. THE SECOND APPEARED "
|
||||
"`bridge label2`_ POINT TO CORRECT TARGET."
|
||||
|
@ -21,7 +21,7 @@ explicit-target
|
||||
.. This case, a duplicated target id is generated by docutils.
|
||||
|
||||
:ref:`explicit-target` point to ``explicit-target`` and
|
||||
`explicit-target`_ point to ``explicit-target`` too.
|
||||
`explicit-target`_ point to duplicated id like ``id1``.
|
||||
|
||||
|
||||
implicit section name
|
||||
@ -61,7 +61,7 @@ label bridged target section
|
||||
|
||||
.. This section is targeted through label definition.
|
||||
|
||||
`bridge label`_ is also translatable and linked to translated section title.
|
||||
`bridge label`_ is not translatable but linked to translated section title.
|
||||
|
||||
`bridge label2`_ point to ``section and label`` and `bridge label`_ point to ``label bridged target section``. The second appeared `bridge label2`_ point to correct target.
|
||||
|
||||
|
@ -436,8 +436,9 @@ def test_i18n_label_target(app):
|
||||
assert_elem(
|
||||
para1[0],
|
||||
texts=['X EXPLICIT-TARGET', 'POINT TO', 'explicit-target', 'AND',
|
||||
'X EXPLICIT-TARGET', 'POINT TO', 'explicit-target', 'TOO.'],
|
||||
refs=['explicit-target', 'explicit-target'])
|
||||
'X EXPLICIT-TARGET', 'POINT TO DUPLICATED ID LIKE', 'id1',
|
||||
'.'],
|
||||
refs=['explicit-target', 'id1'])
|
||||
|
||||
para2 = secs[2].findall('paragraph')
|
||||
assert_elem(
|
||||
@ -457,16 +458,16 @@ def test_i18n_label_target(app):
|
||||
para3 = secs[3].findall('paragraph')
|
||||
assert_elem(
|
||||
para3[0],
|
||||
texts=['X', 'Y BRIDGE LABEL',
|
||||
'IS ALSO TRANSLATABLE AND LINKED TO TRANSLATED ' +
|
||||
texts=['X', 'bridge label',
|
||||
'IS NOT TRANSLATABLE BUT LINKED TO TRANSLATED ' +
|
||||
'SECTION TITLE.'],
|
||||
refs=['label-bridged-target-section'])
|
||||
assert_elem(
|
||||
para3[1],
|
||||
texts=['X', 'Y BRIDGE LABEL', 'POINT TO',
|
||||
'LABEL BRIDGED TARGET SECTION', 'AND', 'Z BRIDGE LABEL2',
|
||||
texts=['X', 'bridge label', 'POINT TO',
|
||||
'LABEL BRIDGED TARGET SECTION', 'AND', 'bridge label2',
|
||||
'POINT TO', 'SECTION AND LABEL', '. THE SECOND APPEARED',
|
||||
'Z BRIDGE LABEL2', 'POINT TO CORRECT TARGET.'],
|
||||
'bridge label2', 'POINT TO CORRECT TARGET.'],
|
||||
refs=['label-bridged-target-section',
|
||||
'section-and-label',
|
||||
'section-and-label'])
|
||||
|
Loading…
Reference in New Issue
Block a user