Takayuki Shimizukawa avatar Takayuki Shimizukawa committed 6fc25e0

fix: reporting correct line number when translations have wrong reST syntax or else.

Comments (0)

Files changed (5)

sphinx/environment.py

             citnode.parent.replace(citnode, refnode)
 
 
+class CustomLocaleReporter(object):
+    """
+    Replacer for document.reporter.get_source_and_line method.
+
+    reST text lines for translation not have original source line number.
+    This class provide correct line number at reporting.
+    """
+    def __init__(self, source, line):
+        self.source, self.line = source, line
+
+    def get_source_and_line(self, lineno=None):
+        return self.source, self.line
+
+
 class Locale(Transform):
     """
     Replace translatable nodes with their translated doctree.
                 # dummy literal node will discard by 'patch = patch[0]'
 
             patch = new_document(source, settings)
+            patch.reporter.get_source_and_line = CustomLocaleReporter(
+                    node.source, node.line).get_source_and_line
             parser.parse(msgstr, patch)
             patch = patch[0]
             # XXX doctest and other block markup

tests/roots/test-intl/contents.txt

 
    subdir/contents
    bom
+   warnings
    footnote
    external_links
    refs_inconsistency

tests/roots/test-intl/warnings.po

+# 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\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 reST warnings"
+msgstr "I18N WITH REST WARNINGS"
+
+msgid "line of ``literal`` markup."
+msgstr "LINE OF ``BROKEN LITERAL MARKUP."

tests/roots/test-intl/warnings.txt

+i18n with reST warnings
+========================
+
+line of ``literal`` markup.
+

tests/test_intl.py

     assert result.startswith(u"\nsubdir contents\n***************\n")
 
 
+@with_intl_app(buildername='text', warning=warnfile)
+def test_i18n_warnings_in_translation(app):
+    app.builddir.rmtree(True)
+    app.builder.build(['warnings'])
+    result = (app.outdir / 'warnings.txt').text(encoding='utf-8')
+    expect = (u"\nI18N WITH REST WARNINGS"
+              u"\n***********************\n"
+              u"\nLINE OF >>``<<BROKEN LITERAL MARKUP.\n")
+
+    assert result == expect
+
+    warnings = warnfile.getvalue().replace(os.sep, '/')
+    warning_expr = u'.*/warnings.txt:4: ' \
+            u'WARNING: Inline literal start-string without end-string.\n'
+    assert re.search(warning_expr, warnings)
+
+
 @with_intl_app(buildername='html', cleanenv=True)
 def test_i18n_footnote_break_refid(app):
     """test for #955 cant-build-html-with-footnotes-when-using"""
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.