mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #3423 from tk0miya/3421_translate_table_caption
Fix #3421: Could not translate a caption of tables
This commit is contained in:
commit
3a67910cf4
1
CHANGES
1
CHANGES
@ -132,6 +132,7 @@ Bugs fixed
|
|||||||
* #3349: Result of ``IndexBuilder.load()`` is broken
|
* #3349: Result of ``IndexBuilder.load()`` is broken
|
||||||
* #3450:   is appeared in EPUB docs
|
* #3450:   is appeared in EPUB docs
|
||||||
* #3418: Search button is misaligned in nature and pyramid theme
|
* #3418: Search button is misaligned in nature and pyramid theme
|
||||||
|
* #3421: Could not translate a caption of tables
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -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
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
# For type annotation
|
# For type annotation
|
||||||
@ -61,10 +62,46 @@ 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):
|
||||||
# type: (Sphinx) -> Dict
|
# type: (Sphinx) -> Dict
|
||||||
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',
|
||||||
|
50
tests/roots/test-intl/table.po
Normal file
50
tests/roots/test-intl/table.po
Normal 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"
|
14
tests/roots/test-intl/table.txt
Normal file
14
tests/roots/test-intl/table.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
:tocdepth: 2
|
||||||
|
|
||||||
|
i18n with table
|
||||||
|
===============
|
||||||
|
|
||||||
|
.. table:: table caption
|
||||||
|
|
||||||
|
======= =======
|
||||||
|
header1 header2
|
||||||
|
------- -------
|
||||||
|
text1 text2
|
||||||
|
text3 text4
|
||||||
|
text5 text6
|
||||||
|
======= =======
|
@ -415,6 +415,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')
|
||||||
|
Loading…
Reference in New Issue
Block a user