Fix #2874: gettext builder could not extract all text under the `only` directives

This commit is contained in:
Takeshi KOMIYA 2016-08-20 20:44:17 +09:00
parent 892cc259ec
commit e96e627d59
5 changed files with 63 additions and 0 deletions

View File

@ -121,6 +121,8 @@ Bugs fixed
`html_translator_class`
* #1797: text builder inserts blank line on top
* #2894: quickstart main() doesn't use argv argument
* #2874: gettext builder could not extract all text under the ``only``
directives
Documentation
-------------

View File

@ -22,6 +22,7 @@ from six import iteritems
from sphinx.builders import Builder
from sphinx.util import split_index_msg
from sphinx.util.tags import Tags
from sphinx.util.nodes import extract_messages, traverse_translatable_index
from sphinx.util.osutil import safe_relpath, ensuredir, canon_path
from sphinx.util.i18n import find_catalog
@ -79,6 +80,16 @@ class MsgOrigin(object):
self.uid = uuid4().hex
class I18nTags(Tags):
"""Dummy tags module for I18nBuilder.
To translate all text inside of only nodes, this class
always returns True value even if no tags are defined.
"""
def eval_condition(self, condition):
return True
class I18nBuilder(Builder):
"""
General i18n builder.
@ -93,6 +104,7 @@ class I18nBuilder(Builder):
def init(self):
Builder.init(self)
self.tags = I18nTags()
self.catalogs = defaultdict(Catalog)
def get_target_uri(self, docname, typ=None):

View File

@ -0,0 +1,29 @@
# 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: 2013-02-04 13: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 "Only directive"
msgstr "ONLY DIRECTIVE"
msgid "In HTML."
msgstr "IN HTML."
msgid "In LaTeX."
msgstr "IN LATEX."
msgid "In both."
msgstr "IN BOTH."

View File

@ -0,0 +1,14 @@
Only directive
--------------
.. only:: html
In HTML.
.. only:: latex
In LaTeX.
.. only:: html or latex
In both.

View File

@ -338,6 +338,12 @@ def test_gettext_builder(app, status, warning):
for expect_msg in [m for m in expect if m.id]:
yield assert_in, expect_msg.id, [m.id for m in actual if m.id]
# --- gettext builder always ignores ``only`` directive
expect = read_po(app.srcdir / 'only.po')
actual = read_po(app.outdir / 'only.pot')
for expect_msg in [m for m in expect if m.id]:
yield assert_in, expect_msg.id, [m.id for m in actual if m.id]
@gen_with_intl_app('html', freshenv=True)
def test_html_builder(app, status, warning):