summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-11-17 02:33:32 +0900
committerGitHub <noreply@github.com>2019-11-17 02:33:32 +0900
commitfcdeafd56e67cc38dcd56862cc0ee6304178a3e8 (patch)
tree9003a5f5505c2f2038aeedb1316de9667adc46c2
parenta8a4daee72cd88206b3811a5d04bb95e122ac6c6 (diff)
parent76c7e07e8dab6eb095a6fb45b88bbaa73764c335 (diff)
downloadsphinx-git-fcdeafd56e67cc38dcd56862cc0ee6304178a3e8.tar.gz
Merge pull request #6784 from tk0miya/4683_more_translatable_toctree
Close #4683: i18n: make explicit titles in toctree translatable
-rw-r--r--CHANGES1
-rw-r--r--sphinx/addnodes.py24
-rw-r--r--tests/roots/test-intl/toctree.txt10
-rw-r--r--tests/roots/test-intl/xx/LC_MESSAGES/toctree.po31
-rw-r--r--tests/test_intl.py24
5 files changed, 87 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index 5933c535c..a1676d5d6 100644
--- a/CHANGES
+++ b/CHANGES
@@ -34,6 +34,7 @@ Features added
* #6812: Improve a warning message when extensions are not parallel safe
* #6818: Improve Intersphinx performance for multiple remote inventories.
* #2546: apidoc: .so file support
+* #6483: i18n: make explicit titles in toctree translatable
Bugs fixed
----------
diff --git a/sphinx/addnodes.py b/sphinx/addnodes.py
index ef3bf3f9e..750e11c20 100644
--- a/sphinx/addnodes.py
+++ b/sphinx/addnodes.py
@@ -63,20 +63,38 @@ class toctree(nodes.General, nodes.Element, translatable):
def preserve_original_messages(self):
# type: () -> None
+ # toctree entries
+ rawentries = self.setdefault('rawentries', [])
+ for title, docname in self['entries']:
+ if title:
+ rawentries.append(title)
+
+ # :caption: option
if self.get('caption'):
self['rawcaption'] = self['caption']
def apply_translated_message(self, original_message, translated_message):
# type: (str, str) -> None
+ # toctree entries
+ for i, (title, docname) in enumerate(self['entries']):
+ if title == original_message:
+ self['entries'][i] = (translated_message, docname)
+
+ # :caption: option
if self.get('rawcaption') == original_message:
self['caption'] = translated_message
def extract_original_messages(self):
# type: () -> List[str]
+ messages = [] # type: List[str]
+
+ # toctree entries
+ messages.extend(self.get('rawentries', []))
+
+ # :caption: option
if 'rawcaption' in self:
- return [self['rawcaption']]
- else:
- return []
+ messages.append(self['rawcaption'])
+ return messages
# domain-specific object descriptions (class, function etc.)
diff --git a/tests/roots/test-intl/toctree.txt b/tests/roots/test-intl/toctree.txt
new file mode 100644
index 000000000..35c956a03
--- /dev/null
+++ b/tests/roots/test-intl/toctree.txt
@@ -0,0 +1,10 @@
+i18n with toctree
+=================
+
+.. toctree::
+ :caption: caption
+
+ figure <figure>
+ table
+ https://www.sphinx-doc.org/
+ self
diff --git a/tests/roots/test-intl/xx/LC_MESSAGES/toctree.po b/tests/roots/test-intl/xx/LC_MESSAGES/toctree.po
new file mode 100644
index 000000000..8ca1dc52c
--- /dev/null
+++ b/tests/roots/test-intl/xx/LC_MESSAGES/toctree.po
@@ -0,0 +1,31 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C)
+# This file is distributed under the same license as the Sphinx intl <Tests> package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: Sphinx intl <Tests> 2013.120\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2019-11-01 10:24+0900\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"
+
+#: ../../toctree.txt:4
+msgid "figure"
+msgstr "FIGURE"
+
+#: ../../toctree.txt:4
+#: ../../toctree.txt:4
+msgid "caption"
+msgstr "CAPTION"
+
+#: ../../toctree.txt:2
+msgid "i18n with toctree"
+msgstr "I18N WITH TOCTREE"
+
diff --git a/tests/test_intl.py b/tests/test_intl.py
index 3815f8357..a6bd17512 100644
--- a/tests/test_intl.py
+++ b/tests/test_intl.py
@@ -468,6 +468,30 @@ def test_text_table(app):
@sphinx_intl
@pytest.mark.sphinx('gettext')
@pytest.mark.test_params(shared_result='test_intl_gettext')
+def test_gettext_toctree(app):
+ app.build()
+ # --- toctree
+ expect = read_po(app.srcdir / 'xx' / 'LC_MESSAGES' / 'toctree.po')
+ actual = read_po(app.outdir / 'toctree.pot')
+ for expect_msg in [m for m in expect if m.id]:
+ assert expect_msg.id in [m.id for m in actual if m.id]
+
+
+@sphinx_intl
+@pytest.mark.sphinx('text')
+@pytest.mark.test_params(shared_result='test_intl_basic')
+def test_text_toctree(app):
+ app.build()
+ # --- toctree
+ result = (app.outdir / 'toctree.txt').text()
+ expect = read_po(app.srcdir / 'xx' / 'LC_MESSAGES' / 'toctree.po')
+ for expect_msg in [m for m in expect if m.id]:
+ assert expect_msg.string in result
+
+
+@sphinx_intl
+@pytest.mark.sphinx('gettext')
+@pytest.mark.test_params(shared_result='test_intl_gettext')
def test_gettext_topic(app):
app.build()
# --- topic