mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix i18n: warnings for translation catalogs have wrong line numbers
This commit is contained in:
parent
0479e1f09b
commit
328ff6eeae
4
CHANGES
4
CHANGES
@ -10,6 +10,9 @@ Incompatible changes
|
|||||||
Deprecated
|
Deprecated
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
* ``sphinx.io.SphinxI18nReader.set_lineno_for_reporter()`` is deprecated
|
||||||
|
* ``sphinx.io.SphinxI18nReader.line`` is deprecated
|
||||||
|
|
||||||
Features added
|
Features added
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
@ -17,6 +20,7 @@ Bugs fixed
|
|||||||
----------
|
----------
|
||||||
|
|
||||||
* html: search box overrides to other elements if scrolled
|
* html: search box overrides to other elements if scrolled
|
||||||
|
* i18n: warnings for translation catalogs have wrong line numbers (refs: #5321)
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -136,6 +136,16 @@ The following is a list of deprecated interface.
|
|||||||
- 4.0
|
- 4.0
|
||||||
- :confval:`autodoc_default_options`
|
- :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``
|
* - ``sphinx.directives.other.VersionChanges``
|
||||||
- 1.8
|
- 1.8
|
||||||
- 3.0
|
- 3.0
|
||||||
|
26
sphinx/io.py
26
sphinx/io.py
@ -10,6 +10,7 @@
|
|||||||
"""
|
"""
|
||||||
import codecs
|
import codecs
|
||||||
import re
|
import re
|
||||||
|
import warnings
|
||||||
|
|
||||||
from docutils.core import Publisher
|
from docutils.core import Publisher
|
||||||
from docutils.io import FileInput, NullOutput
|
from docutils.io import FileInput, NullOutput
|
||||||
@ -20,6 +21,7 @@ from docutils.writers import UnfilteredWriter
|
|||||||
from six import text_type, iteritems
|
from six import text_type, iteritems
|
||||||
from typing import Any, Union # NOQA
|
from typing import Any, Union # NOQA
|
||||||
|
|
||||||
|
from sphinx.deprecation import RemovedInSphinx30Warning
|
||||||
from sphinx.locale import __
|
from sphinx.locale import __
|
||||||
from sphinx.transforms import (
|
from sphinx.transforms import (
|
||||||
ApplySourceWorkaround, ExtraTranslatableNodes, CitationReferences,
|
ApplySourceWorkaround, ExtraTranslatableNodes, CitationReferences,
|
||||||
@ -116,7 +118,6 @@ class SphinxI18nReader(SphinxBaseReader):
|
|||||||
Because the translated texts are partial and they don't have correct line numbers.
|
Because the translated texts are partial and they don't have correct line numbers.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
lineno = None # type: int
|
|
||||||
transforms = [ApplySourceWorkaround, ExtraTranslatableNodes, CitationReferences,
|
transforms = [ApplySourceWorkaround, ExtraTranslatableNodes, CitationReferences,
|
||||||
DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks,
|
DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks,
|
||||||
AutoNumbering, SortIds, RemoveTranslatableInline,
|
AutoNumbering, SortIds, RemoveTranslatableInline,
|
||||||
@ -127,22 +128,15 @@ class SphinxI18nReader(SphinxBaseReader):
|
|||||||
def set_lineno_for_reporter(self, lineno):
|
def set_lineno_for_reporter(self, lineno):
|
||||||
# type: (int) -> None
|
# type: (int) -> None
|
||||||
"""Stores the source line number of original text."""
|
"""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):
|
@property
|
||||||
# type: () -> nodes.document
|
def line(self):
|
||||||
"""Creates a new document object which having a special reporter object for
|
# type: () -> int
|
||||||
translation.
|
warnings.warn('SphinxI18nReader.line is deprecated.',
|
||||||
"""
|
RemovedInSphinx30Warning)
|
||||||
document = SphinxBaseReader.new_document(self)
|
return 0
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class SphinxDummyWriter(UnfilteredWriter):
|
class SphinxDummyWriter(UnfilteredWriter):
|
||||||
|
@ -51,10 +51,10 @@ def publish_msgstr(app, source, source_path, source_line, config, settings):
|
|||||||
"""
|
"""
|
||||||
from sphinx.io import SphinxI18nReader
|
from sphinx.io import SphinxI18nReader
|
||||||
reader = SphinxI18nReader(app)
|
reader = SphinxI18nReader(app)
|
||||||
reader.set_lineno_for_reporter(source_line)
|
|
||||||
parser = app.registry.create_source_parser(app, 'restructuredtext')
|
parser = app.registry.create_source_parser(app, 'restructuredtext')
|
||||||
doc = reader.read(
|
doc = reader.read(
|
||||||
source=StringInput(source=source, source_path=source_path),
|
source=StringInput(source=source,
|
||||||
|
source_path="%s:%s:<translated>" % (source_path, source_line)),
|
||||||
parser=parser,
|
parser=parser,
|
||||||
settings=settings,
|
settings=settings,
|
||||||
)
|
)
|
||||||
|
@ -131,8 +131,8 @@ def test_text_emit_warnings(app, warning):
|
|||||||
app.build()
|
app.build()
|
||||||
# test warnings in translation
|
# test warnings in translation
|
||||||
warnings = getwarning(warning)
|
warnings = getwarning(warning)
|
||||||
warning_expr = u'.*/warnings.txt:4: ' \
|
warning_expr = ('.*/warnings.txt:4:<translated>:1: '
|
||||||
u'WARNING: Inline literal start-string without end-string.\n'
|
'WARNING: Inline literal start-string without end-string.\n')
|
||||||
assert_re_search(warning_expr, warnings)
|
assert_re_search(warning_expr, warnings)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user