From 6698bd6b3f2bc3d15477dd40e7ff6212861334c8 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 17 Mar 2019 15:03:13 +0900 Subject: [PATCH] Fix #6178: i18n: Captions missing in translations for hidden TOCs --- CHANGES | 1 + sphinx/builders/gettext.py | 6 ++++++ tests/roots/test-intl/index.po | 3 +++ tests/roots/test-intl/index.txt | 7 +++++++ tests/test_intl.py | 2 ++ 5 files changed, 19 insertions(+) diff --git a/CHANGES b/CHANGES index b48ee5e75..13281e93f 100644 --- a/CHANGES +++ b/CHANGES @@ -32,6 +32,7 @@ Bugs fixed classes attribute refers missing citation (refs: #6147) * #2155: Support ``code`` directive * C++, fix parsing of braced initializers. +* #6178: i18n: Captions missing in translations for hidden TOCs Testing -------- diff --git a/sphinx/builders/gettext.py b/sphinx/builders/gettext.py index aace9bb49..092d64e2d 100644 --- a/sphinx/builders/gettext.py +++ b/sphinx/builders/gettext.py @@ -16,6 +16,7 @@ from os import path, walk, getenv from time import time from uuid import uuid4 +from sphinx import addnodes from sphinx.builders import Builder from sphinx.domains.python import pairindextypes from sphinx.errors import ThemeError @@ -142,6 +143,11 @@ class I18nBuilder(Builder): # type: (str, nodes.document) -> None catalog = self.catalogs[find_catalog(docname, self.config.gettext_compact)] + for toctree in self.env.tocs[docname].traverse(addnodes.toctree): + for node, msg in extract_messages(toctree): + node.uid = '' # type: ignore # Hack UUID model + catalog.add(msg, node) + for node, msg in extract_messages(doctree): catalog.add(msg, node) diff --git a/tests/roots/test-intl/index.po b/tests/roots/test-intl/index.po index 76ef049f0..a4646f1ec 100644 --- a/tests/roots/test-intl/index.po +++ b/tests/roots/test-intl/index.po @@ -19,6 +19,9 @@ msgstr "" msgid "Table of Contents" msgstr "TABLE OF CONTENTS" +msgid "Hidden Toc" +msgstr "HIDDEN TOC" + msgid "testdata for i18n" msgstr "TESTDATA FOR I18N" diff --git a/tests/roots/test-intl/index.txt b/tests/roots/test-intl/index.txt index cd63b5ec3..1e09294f9 100644 --- a/tests/roots/test-intl/index.txt +++ b/tests/roots/test-intl/index.txt @@ -30,3 +30,10 @@ CONTENTS refs section topic + +.. toctree:: + :maxdepth: 2 + :caption: Hidden Toc + :hidden: + + only diff --git a/tests/test_intl.py b/tests/test_intl.py index 367409fd9..94f8c1d55 100644 --- a/tests/test_intl.py +++ b/tests/test_intl.py @@ -617,6 +617,8 @@ def test_html_meta(app): assert expected_expr in result expected_expr = '' assert expected_expr in result + expected_expr = '

HIDDEN TOC

' + assert expected_expr in result @sphinx_intl