summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2016-08-22 17:48:47 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2016-09-01 23:35:23 +0900
commit15518bad12ddf39730f24249bfa3d6c630fdc9ef (patch)
treebe40f2bb9e12cfe66d5d16ed3e64dd1de0181167
parente1e5ae4b651cb7ad391fb537459155b4a10bade1 (diff)
downloadsphinx-git-15518bad12ddf39730f24249bfa3d6c630fdc9ef.tar.gz
Fix could not translate the content of meta directive (ref: #1734)
-rw-r--r--CHANGES1
-rw-r--r--sphinx/directives/patches.py1
-rw-r--r--sphinx/transforms.py7
-rw-r--r--sphinx/util/nodes.py20
-rw-r--r--tests/roots/test-intl/contents.po6
-rw-r--r--tests/roots/test-intl/contents.txt4
-rw-r--r--tests/test_intl.py8
7 files changed, 46 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index 64b3f9bbb..519672b51 100644
--- a/CHANGES
+++ b/CHANGES
@@ -130,6 +130,7 @@ Bugs fixed
directives
* #2485: autosummary crashes with multiple source_suffix values
* #1734: Could not translate the caption of toctree directive
+* Could not translate the content of meta directive (ref: #1734)
Documentation
-------------
diff --git a/sphinx/directives/patches.py b/sphinx/directives/patches.py
index 6a88db09a..041bee360 100644
--- a/sphinx/directives/patches.py
+++ b/sphinx/directives/patches.py
@@ -47,6 +47,7 @@ class Meta(html.Meta):
meta = node.details['nodes'][0]
meta.source = env.doc2path(env.docname)
meta.line = self.lineno
+ meta.rawcontent = meta['content']
# docutils' meta nodes aren't picklable because the class is nested
meta.__class__ = addnodes.meta
diff --git a/sphinx/transforms.py b/sphinx/transforms.py
index 8792d8f11..9f2aeb8d1 100644
--- a/sphinx/transforms.py
+++ b/sphinx/transforms.py
@@ -22,7 +22,7 @@ from sphinx.locale import _, init as init_locale
from sphinx.util import split_index_msg
from sphinx.util.nodes import (
traverse_translatable_index, extract_messages, LITERAL_TYPE_NODES, IMAGE_TYPE_NODES,
- apply_source_workaround,
+ apply_source_workaround, is_pending_meta,
)
from sphinx.util.i18n import find_catalog, format_date
from sphinx.util.pycompat import indent
@@ -400,6 +400,11 @@ class Locale(Transform):
node.apply_translated_message(msg, msgstr)
continue
+ # update meta nodes
+ if is_pending_meta(node):
+ node.details['nodes'][0]['content'] = msgstr
+ continue
+
# Avoid "Literal block expected; none found." warnings.
# If msgstr ends with '::' then it cause warning message at
# parser.parse() processing.
diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py
index e0a6e0195..cdbf44d76 100644
--- a/sphinx/util/nodes.py
+++ b/sphinx/util/nodes.py
@@ -85,6 +85,14 @@ IGNORED_NODES = (
)
+def is_pending_meta(node):
+ if (isinstance(node, nodes.pending) and
+ isinstance(node.details.get('nodes', [None])[0], addnodes.meta)):
+ return True
+ else:
+ return False
+
+
def is_translatable(node):
if isinstance(node, addnodes.translatable):
return True
@@ -106,6 +114,11 @@ def is_translatable(node):
if isinstance(node, nodes.image) and node.get('translatable'):
return True
+ if isinstance(node, addnodes.meta):
+ return True
+ if is_pending_meta(node):
+ return True
+
return False
@@ -117,6 +130,9 @@ LITERAL_TYPE_NODES = (
IMAGE_TYPE_NODES = (
nodes.image,
)
+META_TYPE_NODES = (
+ addnodes.meta,
+)
def extract_messages(doctree):
@@ -134,6 +150,10 @@ def extract_messages(doctree):
msg = '.. image:: %s' % node['uri']
if node.get('alt'):
msg += '\n :alt: %s' % node['alt']
+ elif isinstance(node, META_TYPE_NODES):
+ msg = node.rawcontent
+ elif is_pending_meta(node):
+ msg = node.details['nodes'][0].rawcontent
else:
msg = node.rawsource.replace('\n', ' ').strip()
diff --git a/tests/roots/test-intl/contents.po b/tests/roots/test-intl/contents.po
index e7f71eafa..76ef049f0 100644
--- a/tests/roots/test-intl/contents.po
+++ b/tests/roots/test-intl/contents.po
@@ -18,3 +18,9 @@ msgstr ""
msgid "Table of Contents"
msgstr "TABLE OF CONTENTS"
+
+msgid "testdata for i18n"
+msgstr "TESTDATA FOR I18N"
+
+msgid "i18n, sphinx, markup"
+msgstr "I18N, SPHINX, MARKUP"
diff --git a/tests/roots/test-intl/contents.txt b/tests/roots/test-intl/contents.txt
index 20542dc81..e2336856c 100644
--- a/tests/roots/test-intl/contents.txt
+++ b/tests/roots/test-intl/contents.txt
@@ -1,6 +1,10 @@
CONTENTS
========
+.. meta::
+ :description: testdata for i18n
+ :keywords: i18n, sphinx, markup
+
.. toctree::
:maxdepth: 2
:numbered:
diff --git a/tests/test_intl.py b/tests/test_intl.py
index 1f7242dfa..80e3eaa64 100644
--- a/tests/test_intl.py
+++ b/tests/test_intl.py
@@ -360,6 +360,14 @@ def test_gettext_builder(app, status, warning):
def test_html_builder(app, status, warning):
app.builder.build_all()
+ # --- test for meta
+
+ result = (app.outdir / 'contents.html').text(encoding='utf-8')
+ expected_expr = '<meta content="TESTDATA FOR I18N" name="description" />'
+ yield assert_in, expected_expr, result
+ expected_expr = '<meta content="I18N, SPHINX, MARKUP" name="keywords" />'
+ yield assert_in, expected_expr, result
+
# --- test for #955 cant-build-html-with-footnotes-when-using
# expect no error by build