summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Lehmann <mail@robertlehmann.de>2010-11-30 14:25:44 +0100
committerRobert Lehmann <mail@robertlehmann.de>2010-11-30 14:25:44 +0100
commit8dc49de95641a85e99b4e0e8d2467618f41cad49 (patch)
tree41b65574952d802df5ac2a406f8ed63af899c09f
parent6c843451b2198803e45e9be07ad85fc956318817 (diff)
parent3de93d83d61a34f3cbad63d04359e9ea1ad3680e (diff)
downloadsphinx-git-8dc49de95641a85e99b4e0e8d2467618f41cad49.tar.gz
merge with trunk
-rw-r--r--sphinx/environment.py10
-rw-r--r--tests/root/subdir.po9
-rw-r--r--tests/test_build_gettext.py55
-rw-r--r--tests/test_intl.py60
4 files changed, 87 insertions, 47 deletions
diff --git a/sphinx/environment.py b/sphinx/environment.py
index 0efdcdd34..3e69baa1b 100644
--- a/sphinx/environment.py
+++ b/sphinx/environment.py
@@ -201,15 +201,13 @@ class Locale(Transform):
# fetch translations
dirs = [path.join(env.srcdir, x)
for x in env.config.locale_dirs]
- catalog, empty = init_locale(dirs, env.config.language, section)
- if not empty:
+ catalog, has_catalog = init_locale(dirs, env.config.language, section)
+ if not has_catalog:
return
parser = RSTParser()
for node, msg in extract_messages(self.document):
- # XXX ctx not used
- #ctx = node.parent
patch = new_document(source, settings)
msgstr = catalog.gettext(msg)
# XXX add marker to untranslated parts
@@ -217,7 +215,9 @@ class Locale(Transform):
continue
parser.parse(msgstr, patch)
patch = patch[0]
- assert isinstance(patch, nodes.paragraph)
+ #XXX doctest and other block markup
+ if not isinstance(patch, nodes.paragraph):
+ continue # skip for now
for child in patch.children: # update leaves
child.parent = node
node.children = patch.children
diff --git a/tests/root/subdir.po b/tests/root/subdir.po
new file mode 100644
index 000000000..f515f2207
--- /dev/null
+++ b/tests/root/subdir.po
@@ -0,0 +1,9 @@
+#, fuzzy
+msgid ""
+msgstr ""
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "Including in subdir"
+msgstr "translation"
diff --git a/tests/test_build_gettext.py b/tests/test_build_gettext.py
index ba2440fd4..ab68289e3 100644
--- a/tests/test_build_gettext.py
+++ b/tests/test_build_gettext.py
@@ -14,6 +14,7 @@ import os
from subprocess import Popen, PIPE
from util import *
+from util import SkipTest
def teardown_module():
@@ -21,13 +22,21 @@ def teardown_module():
@with_app(buildername='gettext')
+def test_all(app):
+ # Generic build; should fail only when the builder is horribly broken.
+ app.builder.build_all()
+
+
+@with_app(buildername='gettext')
def test_build(app):
+ # Do messages end up in the correct location?
app.builder.build(['extapi', 'subdir/includes'])
- # documents end up in a message catalog
+ # top-level documents end up in a message catalog
assert (app.outdir / 'extapi.pot').isfile()
- # ..and are grouped into sections
+ # directory items are grouped into sections
assert (app.outdir / 'subdir.pot').isfile()
+
@with_app(buildername='gettext')
def test_gettext(app):
app.builder.build(['markup'])
@@ -41,7 +50,7 @@ def test_gettext(app):
'--locale', 'en_US'],
stdout=PIPE, stderr=PIPE)
except OSError:
- return # most likely msginit was not found
+ raise SkipTest # most likely msginit was not found
else:
stdout, stderr = p.communicate()
if p.returncode != 0:
@@ -55,7 +64,7 @@ def test_gettext(app):
os.path.join('en', 'LC_MESSAGES', 'test_root.mo')],
stdout=PIPE, stderr=PIPE)
except OSError:
- return # most likely msgfmt was not found
+ raise SkipTest # most likely msgfmt was not found
else:
stdout, stderr = p.communicate()
if p.returncode != 0:
@@ -70,41 +79,3 @@ 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')
-def test_all(app):
- app.builder.build_all()
-
-
-def setup_patch():
- (test_root / 'xx' / 'LC_MESSAGES').makedirs()
- try:
- p = Popen(['msgfmt', test_root / 'bom.po', '-o',
- test_root / 'xx' / 'LC_MESSAGES' / 'bom.mo'],
- stdout=PIPE, stderr=PIPE)
- except OSError:
- return # most likely msgfmt was not found
- else:
- stdout, stderr = p.communicate()
- if p.returncode != 0:
- print stdout
- print stderr
- assert False, 'msgfmt exited with return code %s' % p.returncode
- assert (test_root / 'xx' / 'LC_MESSAGES' / 'bom.mo').isfile(), \
- 'msgfmt failed'
-
-def teardown_patch():
- (test_root / 'xx').rmtree()
-
-@with_app(buildername='text',
- confoverrides={'language': 'xx', 'locale_dirs': ['.']})
-def test_patch(app):
- app.builder.build(['bom'])
- result = (app.outdir / 'bom.txt').text(encoding='utf-8')
- expect = (u"\nDatei mit UTF-8"
- u"\n***************\n" # underline matches new translation
- u"\nThis file has umlauts: äöü.\n")
- assert result == expect
-
-test_patch.setup = setup_patch
-test_patch.teardown = teardown_patch
diff --git a/tests/test_intl.py b/tests/test_intl.py
new file mode 100644
index 000000000..9459a1b76
--- /dev/null
+++ b/tests/test_intl.py
@@ -0,0 +1,60 @@
+# -*- coding: utf-8 -*-
+"""
+ test_intl
+ ~~~~~~~~~
+
+ Test message patching for internationalization purposes. Runs the text
+ builder in the test root.
+
+ :copyright: Copyright 2010 by the Sphinx team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+from subprocess import Popen, PIPE
+
+from util import *
+from util import SkipTest
+
+
+def setup_module():
+ (test_root / 'xx' / 'LC_MESSAGES').makedirs()
+ # Compile all required catalogs into binary format (*.mo).
+ for catalog in 'bom', 'subdir':
+ try:
+ p = Popen(['msgfmt', test_root / '%s.po' % catalog, '-o',
+ test_root / 'xx' / 'LC_MESSAGES' / '%s.mo' % catalog],
+ stdout=PIPE, stderr=PIPE)
+ except OSError:
+ raise SkipTest # most likely msgfmt was not found
+ else:
+ stdout, stderr = p.communicate()
+ if p.returncode != 0:
+ print stdout
+ print stderr
+ assert False, 'msgfmt exited with return code %s' % p.returncode
+ assert (test_root / 'xx' / 'LC_MESSAGES' / ('%s.mo' % catalog)
+ ).isfile(), 'msgfmt failed'
+
+
+def teardown_module():
+ (test_root / '_build').rmtree(True)
+ (test_root / 'xx').rmtree(True)
+
+
+@with_app(buildername='text',
+ confoverrides={'language': 'xx', 'locale_dirs': ['.']})
+def test_simple(app):
+ app.builder.build(['bom'])
+ result = (app.outdir / 'bom.txt').text(encoding='utf-8')
+ expect = (u"\nDatei mit UTF-8"
+ u"\n***************\n" # underline matches new translation
+ u"\nThis file has umlauts: äöü.\n")
+ assert result == expect
+
+
+@with_app(buildername='text',
+ confoverrides={'language': 'xx', 'locale_dirs': ['.']})
+def test_subdir(app):
+ app.builder.build(['subdir/includes'])
+ result = (app.outdir / 'subdir' / 'includes.txt').text(encoding='utf-8')
+ assert result.startswith(u"\ntranslation\n***********\n\n")