diff --git a/CHANGES b/CHANGES index 87879d4bb..ede52706d 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,9 @@ Incompatible changes Deprecated ---------- +* ``sphinx.io.SphinxI18nReader.set_lineno_for_reporter()`` is deprecated +* ``sphinx.io.SphinxI18nReader.line`` is deprecated + Features added -------------- @@ -17,6 +20,7 @@ Bugs fixed ---------- * html: search box overrides to other elements if scrolled +* i18n: warnings for translation catalogs have wrong line numbers (refs: #5321) * #5325: latex: cross references has been broken by multiply labeled objects Testing diff --git a/doc/extdev/index.rst b/doc/extdev/index.rst index 6e8bdd41d..13a08e49b 100644 --- a/doc/extdev/index.rst +++ b/doc/extdev/index.rst @@ -136,6 +136,16 @@ The following is a list of deprecated interface. - 4.0 - :confval:`autodoc_default_options` + * - ``sphinx.io.SphinxI18nReader.set_lineno_for_reporter()`` + - 1.8 + - 3.0 + - N/A + + * - ``sphinx.io.SphinxI18nReader.line`` + - 1.8 + - 3.0 + - N/A + * - ``sphinx.directives.other.VersionChanges`` - 1.8 - 3.0 diff --git a/sphinx/io.py b/sphinx/io.py index c90090e74..ad76c2afb 100644 --- a/sphinx/io.py +++ b/sphinx/io.py @@ -10,6 +10,7 @@ """ import codecs import re +import warnings from docutils.core import Publisher from docutils.io import FileInput, NullOutput @@ -20,6 +21,7 @@ from docutils.writers import UnfilteredWriter from six import text_type, iteritems from typing import Any, Union # NOQA +from sphinx.deprecation import RemovedInSphinx30Warning from sphinx.locale import __ from sphinx.transforms import ( ApplySourceWorkaround, ExtraTranslatableNodes, CitationReferences, @@ -116,7 +118,6 @@ class SphinxI18nReader(SphinxBaseReader): Because the translated texts are partial and they don't have correct line numbers. """ - lineno = None # type: int transforms = [ApplySourceWorkaround, ExtraTranslatableNodes, CitationReferences, DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks, AutoNumbering, SortIds, RemoveTranslatableInline, @@ -127,22 +128,15 @@ class SphinxI18nReader(SphinxBaseReader): def set_lineno_for_reporter(self, lineno): # type: (int) -> None """Stores the source line number of original text.""" - self.lineno = lineno + warnings.warn('SphinxI18nReader.set_lineno_for_reporter() is deprecated.', + RemovedInSphinx30Warning) - def new_document(self): - # type: () -> nodes.document - """Creates a new document object which having a special reporter object for - translation. - """ - document = SphinxBaseReader.new_document(self) - reporter = document.reporter - - def get_source_and_line(lineno=None): - # type: (int) -> Tuple[unicode, int] - return reporter.source, self.lineno - - reporter.get_source_and_line = get_source_and_line - return document + @property + def line(self): + # type: () -> int + warnings.warn('SphinxI18nReader.line is deprecated.', + RemovedInSphinx30Warning) + return 0 class SphinxDummyWriter(UnfilteredWriter): diff --git a/sphinx/transforms/i18n.py b/sphinx/transforms/i18n.py index ead17261f..f49e27df3 100644 --- a/sphinx/transforms/i18n.py +++ b/sphinx/transforms/i18n.py @@ -51,10 +51,10 @@ def publish_msgstr(app, source, source_path, source_line, config, settings): """ from sphinx.io import SphinxI18nReader reader = SphinxI18nReader(app) - reader.set_lineno_for_reporter(source_line) parser = app.registry.create_source_parser(app, 'restructuredtext') doc = reader.read( - source=StringInput(source=source, source_path=source_path), + source=StringInput(source=source, + source_path="%s:%s:" % (source_path, source_line)), parser=parser, settings=settings, ) diff --git a/tests/test_intl.py b/tests/test_intl.py index 71b916781..c8f90e41c 100644 --- a/tests/test_intl.py +++ b/tests/test_intl.py @@ -131,8 +131,8 @@ def test_text_emit_warnings(app, warning): app.build() # test warnings in translation warnings = getwarning(warning) - warning_expr = u'.*/warnings.txt:4: ' \ - u'WARNING: Inline literal start-string without end-string.\n' + warning_expr = ('.*/warnings.txt:4::1: ' + 'WARNING: Inline literal start-string without end-string.\n') assert_re_search(warning_expr, warnings)