use `nodes.inline` with a "translatable" attr instead

This commit is contained in:
Nozomu Kaneko 2013-01-13 02:14:00 +09:00
parent d2a087e88d
commit 58c0c79c17
3 changed files with 11 additions and 14 deletions

View File

@ -321,9 +321,9 @@ class Locale(Transform):
node['entries'] = new_entries node['entries'] = new_entries
class DocFields(Transform): class RemoveTranslatableInline(Transform):
""" """
Remove nested paragraphs generated by docfields. Remove inline nodes used for translation as placeholders.
""" """
default_priority = 999 default_priority = 999
@ -333,14 +333,10 @@ class DocFields(Transform):
builder = env.app.builder builder = env.app.builder
if isinstance(builder, MessageCatalogBuilder): if isinstance(builder, MessageCatalogBuilder):
return return
for field_list in self.document.traverse(nodes.field_list): for inline in self.document.traverse(nodes.inline):
for field_body in field_list.traverse(nodes.field_body): if 'translatable' in inline:
for par in field_list.traverse(nodes.paragraph): inline.parent.remove(inline)
if not ('removable' in par and inline.parent += inline.children
isinstance(par.parent, nodes.paragraph)):
continue
par.parent.remove(par)
par.parent += par.children
class SphinxStandaloneReader(standalone.Reader): class SphinxStandaloneReader(standalone.Reader):
@ -348,7 +344,8 @@ class SphinxStandaloneReader(standalone.Reader):
Add our own transforms. Add our own transforms.
""" """
transforms = [Locale, CitationReferences, DefaultSubstitutions, transforms = [Locale, CitationReferences, DefaultSubstitutions,
MoveModuleTargets, HandleCodeBlocks, SortIds, DocFields] MoveModuleTargets, HandleCodeBlocks, SortIds,
RemoveTranslatableInline]
def get_transforms(self): def get_transforms(self):
return standalone.Reader.get_transforms(self) + self.transforms return standalone.Reader.get_transforms(self) + self.transforms

View File

@ -255,8 +255,8 @@ class DocFieldTransformer(object):
[nodes.Text(argtype)] [nodes.Text(argtype)]
fieldarg = argname fieldarg = argname
translatable_content = nodes.paragraph(fieldbody.rawsource, translatable_content = nodes.inline(fieldbody.rawsource,
removable=True) translatable=True)
translatable_content.source = fieldbody.parent.source translatable_content.source = fieldbody.parent.source
translatable_content.line = fieldbody.parent.line translatable_content.line = fieldbody.parent.line
translatable_content += content translatable_content += content

View File

@ -61,7 +61,7 @@ def extract_messages(doctree):
if not node.source: if not node.source:
continue # built-in message continue # built-in message
if isinstance(node, IGNORED_NODES): if isinstance(node, IGNORED_NODES) and 'translatable' not in node:
continue continue
# <field_name>orphan</field_name> # <field_name>orphan</field_name>
# XXX ignore all metadata (== docinfo) # XXX ignore all metadata (== docinfo)