mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Closes #976: Fix gettext does not extract index entries.
This commit is contained in:
@@ -8,3 +8,4 @@
|
||||
literalblock
|
||||
definition_terms
|
||||
figure_caption
|
||||
index_entries
|
||||
|
||||
77
tests/root/i18n/index_entries.po
Normal file
77
tests/root/i18n/index_entries.po
Normal file
@@ -0,0 +1,77 @@
|
||||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) 2013, foo
|
||||
# This file is distributed under the same license as the foo package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: foo foo\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2013-01-05 18:10\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 index entries"
|
||||
msgstr ""
|
||||
|
||||
msgid "index target section"
|
||||
msgstr ""
|
||||
|
||||
msgid "this is :index:`Newsletter` target paragraph."
|
||||
msgstr "THIS IS :index:`NEWSLETTER` TARGET PARAGRAPH."
|
||||
|
||||
msgid "various index entries"
|
||||
msgstr ""
|
||||
|
||||
msgid "That's all."
|
||||
msgstr ""
|
||||
|
||||
msgid "Mailing List"
|
||||
msgstr "MAILING LIST"
|
||||
|
||||
msgid "Newsletter"
|
||||
msgstr "NEWSLETTER"
|
||||
|
||||
msgid "Recipients List"
|
||||
msgstr "RECIPIENTS LIST"
|
||||
|
||||
msgid "First"
|
||||
msgstr "FIRST"
|
||||
|
||||
msgid "Second"
|
||||
msgstr "SECOND"
|
||||
|
||||
msgid "Third"
|
||||
msgstr "THIRD"
|
||||
|
||||
msgid "Entry"
|
||||
msgstr "ENTRY"
|
||||
|
||||
msgid "See"
|
||||
msgstr "SEE"
|
||||
|
||||
msgid "Module"
|
||||
msgstr "MODULE"
|
||||
|
||||
msgid "Keyword"
|
||||
msgstr "KEYWORD"
|
||||
|
||||
msgid "Operator"
|
||||
msgstr "OPERATOR"
|
||||
|
||||
msgid "Object"
|
||||
msgstr "OBJECT"
|
||||
|
||||
msgid "Exception"
|
||||
msgstr "EXCEPTION"
|
||||
|
||||
msgid "Statement"
|
||||
msgstr "STATEMENT"
|
||||
|
||||
msgid "Builtin"
|
||||
msgstr "BUILTIN"
|
||||
31
tests/root/i18n/index_entries.txt
Normal file
31
tests/root/i18n/index_entries.txt
Normal file
@@ -0,0 +1,31 @@
|
||||
:tocdepth: 2
|
||||
|
||||
i18n with index entries
|
||||
=======================
|
||||
|
||||
.. index::
|
||||
single: Mailing List
|
||||
pair: Newsletter; Recipients List
|
||||
|
||||
index target section
|
||||
--------------------
|
||||
|
||||
this is :index:`Newsletter` target paragraph.
|
||||
|
||||
|
||||
various index entries
|
||||
---------------------
|
||||
|
||||
.. index::
|
||||
triple: First; Second; Third
|
||||
see: Entry; Mailing List
|
||||
seealso: See; Newsletter
|
||||
module: Module
|
||||
keyword: Keyword
|
||||
operator: Operator
|
||||
object: Object
|
||||
exception: Exception
|
||||
statement: Statement
|
||||
builtin: Builtin
|
||||
|
||||
That's all.
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
import gettext
|
||||
import os
|
||||
import re
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
from util import *
|
||||
@@ -79,3 +80,49 @@ def test_gettext(app):
|
||||
|
||||
_ = gettext.translation('test_root', app.outdir, languages=['en']).gettext
|
||||
assert _("Testing various markup") == u"Testing various markup"
|
||||
|
||||
|
||||
@with_app(buildername='gettext',
|
||||
confoverrides={'gettext_compact': False})
|
||||
def test_gettext_index_entries(app):
|
||||
# regression test for #976
|
||||
app.builder.build(['i18n/index_entries'])
|
||||
|
||||
_msgid_getter = re.compile(r'msgid "(.*)"').search
|
||||
def msgid_getter(msgid):
|
||||
m = _msgid_getter(msgid)
|
||||
if m:
|
||||
return m.groups()[0]
|
||||
return None
|
||||
|
||||
pot = (app.outdir / 'i18n' / 'index_entries.pot').text(encoding='utf-8')
|
||||
msgids = filter(None, map(msgid_getter, pot.splitlines()))
|
||||
|
||||
expected_msgids = [
|
||||
"i18n with index entries",
|
||||
"index target section",
|
||||
"this is :index:`Newsletter` target paragraph.",
|
||||
"various index entries",
|
||||
"That's all.",
|
||||
"Mailing List",
|
||||
"Newsletter",
|
||||
"Recipients List",
|
||||
"First",
|
||||
"Second",
|
||||
"Third",
|
||||
"Entry",
|
||||
"See",
|
||||
"Module",
|
||||
"Keyword",
|
||||
"Operator",
|
||||
"Object",
|
||||
"Exception",
|
||||
"Statement",
|
||||
"Builtin",
|
||||
]
|
||||
for expect in expected_msgids:
|
||||
assert expect in msgids
|
||||
msgids.remove(expect)
|
||||
|
||||
# unexpected msgid existent
|
||||
assert msgids == []
|
||||
|
||||
@@ -259,3 +259,37 @@ def test_i18n_figure_caption(app):
|
||||
u"\n MY DESCRIPTION PARAGRAPH2 OF THE FIGURE.\n")
|
||||
|
||||
assert result == expect
|
||||
|
||||
|
||||
@with_app(buildername='html',
|
||||
confoverrides={'language': 'xx', 'locale_dirs': ['.'],
|
||||
'gettext_compact': False})
|
||||
def test_i18n_index_entries(app):
|
||||
# regression test for #976
|
||||
app.builder.build(['i18n/index_entries'])
|
||||
result = (app.outdir / 'genindex.html').text(encoding='utf-8')
|
||||
|
||||
def wrap(tag, keyword):
|
||||
start_tag = "<%s[^>]*>" % tag
|
||||
end_tag = "</%s>" % tag
|
||||
return r"%s\s*%s\s*%s" % (start_tag, keyword, end_tag)
|
||||
|
||||
expected_exprs = [
|
||||
wrap('a', 'NEWSLETTER'),
|
||||
wrap('a', 'MAILING LIST'),
|
||||
wrap('a', 'RECIPIENTS LIST'),
|
||||
wrap('a', 'FIRST SECOND'),
|
||||
wrap('a', 'SECOND THIRD'),
|
||||
wrap('a', 'THIRD, FIRST'),
|
||||
wrap('dt', 'ENTRY'),
|
||||
wrap('dt', 'SEE'),
|
||||
wrap('a', 'MODULE'),
|
||||
wrap('a', 'KEYWORD'),
|
||||
wrap('a', 'OPERATOR'),
|
||||
wrap('a', 'OBJECT'),
|
||||
wrap('a', 'EXCEPTION'),
|
||||
wrap('a', 'STATEMENT'),
|
||||
wrap('a', 'BUILTIN'),
|
||||
]
|
||||
for expr in expected_exprs:
|
||||
assert re.search(expr, result, re.M)
|
||||
|
||||
Reference in New Issue
Block a user