From 1d0083edc5752d44f1fdd96d9b32bce24eeedac2 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 15 Feb 2017 18:08:54 +0900 Subject: [PATCH] Fix #3421: Could not translate a caption of tables --- CHANGES | 2 +- sphinx/directives/patches.py | 39 ++++++++++++++++++++++++- tests/roots/test-intl/table.po | 50 +++++++++++++++++++++++++++++++++ tests/roots/test-intl/table.txt | 14 +++++++++ tests/test_intl.py | 12 ++++++++ 5 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 tests/roots/test-intl/table.po create mode 100644 tests/roots/test-intl/table.txt diff --git a/CHANGES b/CHANGES index de978268e..98f72ee49 100644 --- a/CHANGES +++ b/CHANGES @@ -34,7 +34,7 @@ Bugs fixed * #3349: Result of ``IndexBuilder.load()`` is broken * #3450:   is appeared in EPUB docs * #3418: Search button is misaligned in nature and pyramid theme - +* #3421: Could not translate a caption of tables Testing -------- diff --git a/sphinx/directives/patches.py b/sphinx/directives/patches.py index 8b14ba2b0..2348b1357 100644 --- a/sphinx/directives/patches.py +++ b/sphinx/directives/patches.py @@ -9,9 +9,10 @@ from docutils import nodes from docutils.parsers.rst import directives -from docutils.parsers.rst.directives import images, html +from docutils.parsers.rst.directives import images, html, tables from sphinx import addnodes +from sphinx.util.nodes import set_source_info class Figure(images.Figure): @@ -55,9 +56,45 @@ class Meta(html.Meta): return result +class RSTTable(tables.RSTTable): + """The table directive which sets source and line information to its caption.""" + + def make_title(self): + title, message = tables.RSTTable.make_title(self) + if title: + set_source_info(self, title) + + return title, message + + +class CSVTable(tables.CSVTable): + """The csv-table directive which sets source and line information to its caption.""" + + def make_title(self): + title, message = tables.CSVTable.make_title(self) + if title: + set_source_info(self, title) + + return title, message + + +class ListTable(tables.ListTable): + """The list-table directive which sets source and line information to its caption.""" + + def make_title(self): + title, message = tables.ListTable.make_title(self) + if title: + set_source_info(self, title) + + return title, message + + def setup(app): directives.register_directive('figure', Figure) directives.register_directive('meta', Meta) + directives.register_directive('table', RSTTable) + directives.register_directive('csv-table', CSVTable) + directives.register_directive('list-table', ListTable) return { 'version': 'builtin', diff --git a/tests/roots/test-intl/table.po b/tests/roots/test-intl/table.po new file mode 100644 index 000000000..9f8d687c3 --- /dev/null +++ b/tests/roots/test-intl/table.po @@ -0,0 +1,50 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2010, Georg Brandl & Team +# This file is distributed under the same license as the Sphinx package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: Sphinx 0.6\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-12-16 06:06+0000\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "i18n with table" +msgstr "I18N WITH TABLE" + +msgid "table caption" +msgstr "TABLE CAPTION" + +msgid "header1" +msgstr "HEADER1" + +msgid "header2" +msgstr "HEADER2" + +msgid "text1" +msgstr "TEXT1" + +msgid "text2" +msgstr "TEXT2" + +msgid "text3" +msgstr "TEXT3" + +msgid "text1" +msgstr "TEXT1" + +msgid "text4" +msgstr "TEXT4" + +msgid "text5" +msgstr "TEXT5" + +msgid "text6" +msgstr "TEXT6" diff --git a/tests/roots/test-intl/table.txt b/tests/roots/test-intl/table.txt new file mode 100644 index 000000000..2eab86248 --- /dev/null +++ b/tests/roots/test-intl/table.txt @@ -0,0 +1,14 @@ +:tocdepth: 2 + +i18n with table +=============== + +.. table:: table caption + + ======= ======= + header1 header2 + ------- ------- + text1 text2 + text3 text4 + text5 text6 + ======= ======= diff --git a/tests/test_intl.py b/tests/test_intl.py index f8047d14f..7b92698e9 100644 --- a/tests/test_intl.py +++ b/tests/test_intl.py @@ -414,6 +414,18 @@ def test_gettext_toctree(app): assert expect_msg.id in [m.id for m in actual if m.id] +@sphinx_intl +@pytest.mark.sphinx('gettext') +@pytest.mark.test_params(shared_result='test_intl_gettext') +def test_gettext_table(app): + app.build() + # --- toctree + expect = read_po(app.srcdir / 'table.po') + actual = read_po(app.outdir / 'table.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('gettext') @pytest.mark.test_params(shared_result='test_intl_gettext')