mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #2878 from tk0miya/2874_gettext_builder_should_ignore_only_directive
Fix #2874: gettext builder could not extract all text under the ``only`` directives
This commit is contained in:
commit
f2d044bb73
2
CHANGES
2
CHANGES
@ -124,6 +124,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
|
||||
-------------
|
||||
|
@ -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):
|
||||
|
29
tests/roots/test-intl/only.po
Normal file
29
tests/roots/test-intl/only.po
Normal 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."
|
14
tests/roots/test-intl/only.txt
Normal file
14
tests/roots/test-intl/only.txt
Normal file
@ -0,0 +1,14 @@
|
||||
Only directive
|
||||
--------------
|
||||
|
||||
.. only:: html
|
||||
|
||||
In HTML.
|
||||
|
||||
.. only:: latex
|
||||
|
||||
In LaTeX.
|
||||
|
||||
.. only:: html or latex
|
||||
|
||||
In both.
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user