diff --git a/CHANGES b/CHANGES index ca5ef0e76..d1097f2f4 100644 --- a/CHANGES +++ b/CHANGES @@ -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 ------------- diff --git a/sphinx/builders/gettext.py b/sphinx/builders/gettext.py index aa9400575..bc74f7177 100644 --- a/sphinx/builders/gettext.py +++ b/sphinx/builders/gettext.py @@ -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): diff --git a/tests/roots/test-intl/only.po b/tests/roots/test-intl/only.po new file mode 100644 index 000000000..43eb7d60f --- /dev/null +++ b/tests/roots/test-intl/only.po @@ -0,0 +1,29 @@ +# 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: 2013-02-04 13: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 "Only directive" +msgstr "ONLY DIRECTIVE" + +msgid "In HTML." +msgstr "IN HTML." + +msgid "In LaTeX." +msgstr "IN LATEX." + +msgid "In both." +msgstr "IN BOTH." diff --git a/tests/roots/test-intl/only.txt b/tests/roots/test-intl/only.txt new file mode 100644 index 000000000..2c8990e5f --- /dev/null +++ b/tests/roots/test-intl/only.txt @@ -0,0 +1,14 @@ +Only directive +-------------- + +.. only:: html + + In HTML. + +.. only:: latex + + In LaTeX. + +.. only:: html or latex + + In both. diff --git a/tests/test_intl.py b/tests/test_intl.py index b217028a3..de1d56e33 100644 --- a/tests/test_intl.py +++ b/tests/test_intl.py @@ -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):