Fix #3421: Could not translate a caption of tables

This commit is contained in:
Takeshi KOMIYA
2017-02-15 18:08:54 +09:00
parent b9bba672ed
commit 6b7dcf0889
5 changed files with 115 additions and 1 deletions

View File

@@ -27,6 +27,7 @@ Bugs fixed
gets wrong PDF page dimensions gets wrong PDF page dimensions
* #3399: quickstart: conf.py was not overwritten by template * #3399: quickstart: conf.py was not overwritten by template
* #3366: option directive does not allow punctuations * #3366: option directive does not allow punctuations
* #3421: Could not translate a caption of tables
Testing Testing
-------- --------

View File

@@ -9,9 +9,10 @@
from docutils import nodes from docutils import nodes
from docutils.parsers.rst import directives 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 import addnodes
from sphinx.util.nodes import set_source_info
class Figure(images.Figure): class Figure(images.Figure):
@@ -55,9 +56,45 @@ class Meta(html.Meta):
return result 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): def setup(app):
directives.register_directive('figure', Figure) directives.register_directive('figure', Figure)
directives.register_directive('meta', Meta) directives.register_directive('meta', Meta)
directives.register_directive('table', RSTTable)
directives.register_directive('csv-table', CSVTable)
directives.register_directive('list-table', ListTable)
return { return {
'version': 'builtin', 'version': 'builtin',

View File

@@ -0,0 +1,50 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2010, Georg Brandl & Team
# This file is distributed under the same license as the Sphinx <Tests> package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Sphinx <Tests> 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 <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"
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"

View File

@@ -0,0 +1,14 @@
:tocdepth: 2
i18n with table
===============
.. table:: table caption
======= =======
header1 header2
------- -------
text1 text2
text3 text4
text5 text6
======= =======

View File

@@ -414,6 +414,18 @@ def test_gettext_toctree(app):
assert expect_msg.id in [m.id for m in actual 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')
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 @sphinx_intl
@pytest.mark.sphinx('gettext') @pytest.mark.sphinx('gettext')
@pytest.mark.test_params(shared_result='test_intl_gettext') @pytest.mark.test_params(shared_result='test_intl_gettext')