diff options
| author | shimizukawa <shimizukawa@gmail.com> | 2013-02-04 22:23:03 +0900 |
|---|---|---|
| committer | shimizukawa <shimizukawa@gmail.com> | 2013-02-04 22:23:03 +0900 |
| commit | 557979af85df90414188e2149686ea46e9102e5a (patch) | |
| tree | 12db1f6dcfc34eecccc2d307a72ed390755730e5 | |
| parent | 38a9f1a75a12ae3227e65f29f8c5e6a47e39e8e9 (diff) | |
| download | sphinx-557979af85df90414188e2149686ea46e9102e5a.tar.gz | |
fix: reporting correct line number when translations have wrong reST syntax or else.
| -rw-r--r-- | sphinx/environment.py | 16 | ||||
| -rw-r--r-- | tests/roots/test-intl/contents.txt | 1 | ||||
| -rw-r--r-- | tests/roots/test-intl/warnings.po | 23 | ||||
| -rw-r--r-- | tests/roots/test-intl/warnings.txt | 5 | ||||
| -rw-r--r-- | tests/test_intl.py | 17 |
5 files changed, 62 insertions, 0 deletions
diff --git a/sphinx/environment.py b/sphinx/environment.py index 2995cbbc..2e70569b 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -189,6 +189,20 @@ class CitationReferences(Transform): 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. @@ -229,6 +243,8 @@ class Locale(Transform): # 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 diff --git a/tests/roots/test-intl/contents.txt b/tests/roots/test-intl/contents.txt index a08cb0d3..932a58dd 100644 --- a/tests/roots/test-intl/contents.txt +++ b/tests/roots/test-intl/contents.txt @@ -4,6 +4,7 @@ subdir/contents bom + warnings footnote external_links refs_inconsistency diff --git a/tests/roots/test-intl/warnings.po b/tests/roots/test-intl/warnings.po new file mode 100644 index 00000000..bf82510e --- /dev/null +++ b/tests/roots/test-intl/warnings.po @@ -0,0 +1,23 @@ +# 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." diff --git a/tests/roots/test-intl/warnings.txt b/tests/roots/test-intl/warnings.txt new file mode 100644 index 00000000..a80fe183 --- /dev/null +++ b/tests/roots/test-intl/warnings.txt @@ -0,0 +1,5 @@ +i18n with reST warnings +======================== + +line of ``literal`` markup. + diff --git a/tests/test_intl.py b/tests/test_intl.py index 06181c3b..9336bead 100644 --- a/tests/test_intl.py +++ b/tests/test_intl.py @@ -89,6 +89,23 @@ def test_subdir(app): 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""" |
