Takayuki Shimizukawa avatar Takayuki Shimizukawa committed e2338c4

Avoid unusable warning in using i18n translation. Closes #1057.
And there is related information at pull request #86

Comments (0)

Files changed (6)

sphinx/environment.py

             if not msgstr or msgstr == msg: # as-of-yet untranslated
                 continue
 
+            # Avoid "Literal block expected; none found." warnings.
+            # If msgstr ends with '::' then it cause warning message at
+            # parser.parse() processing.
+            # literal-block-warning is only appear in avobe case.
+            if msgstr.strip().endswith('::'):
+                msgstr += '\n\n   dummy literal'
+                # dummy literal node will discard by 'patch = patch[0]'
+
             patch = new_document(source, settings)
             parser.parse(msgstr, patch)
             patch = patch[0]

tests/root/i18n/index.txt

    footnote
    external_links
    refs_inconsistency
+   literalblock

tests/root/i18n/literalblock.po

+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) 2012, foof
+# This file is distributed under the same license as the foo package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: sphinx 1.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-11-22 08:28\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 literal block"
+msgstr "I18N WITH LITERAL BLOCK"
+
+msgid "Correct literal block::"
+msgstr "CORRECT LITERAL BLOCK::"
+
+msgid "Missing literal block::"
+msgstr "MISSING LITERAL BLOCK::"
+
+msgid "That's all."
+msgstr "THAT'S ALL."
+

tests/root/i18n/literalblock.txt

+:tocdepth: 2
+
+i18n with literal block
+=========================
+
+Correct literal block::
+
+   this is
+   literal block
+
+Missing literal block::
+
+That's all.

tests/test_build_html.py

 %(root)s/autodoc_fodder.py:docstring of autodoc_fodder\\.MarkupError:2: \
 WARNING: Explicit markup ends without a blank line; unexpected \
 unindent\\.\\n?
+%(root)s/i18n/literalblock.txt:13: WARNING: Literal block expected; none found.
 %(root)s/images.txt:9: WARNING: image file not readable: foo.png
 %(root)s/images.txt:23: WARNING: nonlocal image URI found: \
 http://www.python.org/logo.png

tests/test_intl.py

     if matched:
         matched_line = matched.group()
     assert expect_line == matched_line
+
+
+@with_app(buildername='text', warning=warnfile, cleanenv=True,
+          confoverrides={'language': 'xx', 'locale_dirs': ['.'],
+                         'gettext_compact': False})
+def test_i18n_literalblock_warning(app):
+    app.builddir.rmtree(True)  #for warnings acceleration
+    app.builder.build(['i18n/literalblock'])
+    result = (app.outdir / 'i18n' / 'literalblock.txt').text(encoding='utf-8')
+    expect = (u"\nI18N WITH LITERAL BLOCK"
+              u"\n***********************\n"
+              u"\nCORRECT LITERAL BLOCK:\n"
+              u"\n   this is"
+              u"\n   literal block\n"
+              u"\nMISSING LITERAL BLOCK:\n"
+              u"\n<SYSTEM MESSAGE: ")
+    assert result.startswith(expect)
+
+    warnings = warnfile.getvalue().replace(os.sep, '/')
+    expected_warning_expr = u'.*/i18n/literalblock.txt:\\d+: ' \
+            u'WARNING: Literal block expected; none found.'
+    assert re.search(expected_warning_expr, warnings)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.