mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #6927 from tk0miya/6856_i18n_parser
Fix #6855: Non-RST translated text should be parsed by the appropriate parser
This commit is contained in:
commit
de6184e43f
3
CHANGES
3
CHANGES
@ -10,6 +10,9 @@ Incompatible changes
|
|||||||
Deprecated
|
Deprecated
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
* ``sphinx.io.FiletypeNotFoundError``
|
||||||
|
* ``sphinx.io.get_filetype()``
|
||||||
|
|
||||||
Features added
|
Features added
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
@ -26,6 +26,16 @@ The following is a list of deprecated interfaces.
|
|||||||
- (will be) Removed
|
- (will be) Removed
|
||||||
- Alternatives
|
- Alternatives
|
||||||
|
|
||||||
|
* - ``sphinx.io.FiletypeNotFoundError``
|
||||||
|
- 2.4
|
||||||
|
- 4.0
|
||||||
|
- ``sphinx.errors.FiletypeNotFoundError``
|
||||||
|
|
||||||
|
* - ``sphinx.io.get_filetype()``
|
||||||
|
- 2.4
|
||||||
|
- 4.0
|
||||||
|
- ``sphinx.util.get_filetype()``
|
||||||
|
|
||||||
* - ``sphinx.builders.gettext.POHEADER``
|
* - ``sphinx.builders.gettext.POHEADER``
|
||||||
- 2.3
|
- 2.3
|
||||||
- 4.0
|
- 4.0
|
||||||
|
@ -126,3 +126,8 @@ class PycodeError(Exception):
|
|||||||
class NoUri(Exception):
|
class NoUri(Exception):
|
||||||
"""Raised by builder.get_relative_uri() if there is no URI available."""
|
"""Raised by builder.get_relative_uri() if there is no URI available."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class FiletypeNotFoundError(Exception):
|
||||||
|
"Raised by get_filetype() if a filename matches no source suffix."
|
||||||
|
pass
|
||||||
|
29
sphinx/io.py
29
sphinx/io.py
@ -19,7 +19,10 @@ from docutils.statemachine import StringList, string2lines
|
|||||||
from docutils.transforms.references import DanglingReferences
|
from docutils.transforms.references import DanglingReferences
|
||||||
from docutils.writers import UnfilteredWriter
|
from docutils.writers import UnfilteredWriter
|
||||||
|
|
||||||
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
|
from sphinx.deprecation import (
|
||||||
|
RemovedInSphinx30Warning, RemovedInSphinx40Warning, deprecated_alias
|
||||||
|
)
|
||||||
|
from sphinx.errors import FiletypeNotFoundError
|
||||||
from sphinx.transforms import (
|
from sphinx.transforms import (
|
||||||
AutoIndexUpgrader, DoctreeReadEvent, FigureAligner, SphinxTransformer
|
AutoIndexUpgrader, DoctreeReadEvent, FigureAligner, SphinxTransformer
|
||||||
)
|
)
|
||||||
@ -27,7 +30,7 @@ from sphinx.transforms.i18n import (
|
|||||||
PreserveTranslatableMessages, Locale, RemoveTranslatableInline,
|
PreserveTranslatableMessages, Locale, RemoveTranslatableInline,
|
||||||
)
|
)
|
||||||
from sphinx.transforms.references import SphinxDomains
|
from sphinx.transforms.references import SphinxDomains
|
||||||
from sphinx.util import logging
|
from sphinx.util import logging, get_filetype
|
||||||
from sphinx.util import UnicodeDecodeErrorHandler
|
from sphinx.util import UnicodeDecodeErrorHandler
|
||||||
from sphinx.util.docutils import LoggingReporter
|
from sphinx.util.docutils import LoggingReporter
|
||||||
from sphinx.util.rst import append_epilog, docinfo_re, prepend_prolog
|
from sphinx.util.rst import append_epilog, docinfo_re, prepend_prolog
|
||||||
@ -292,20 +295,6 @@ class SphinxRSTFileInput(SphinxBaseFileInput):
|
|||||||
return lineno
|
return lineno
|
||||||
|
|
||||||
|
|
||||||
class FiletypeNotFoundError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def get_filetype(source_suffix, filename):
|
|
||||||
# type: (Dict[str, str], str) -> str
|
|
||||||
for suffix, filetype in source_suffix.items():
|
|
||||||
if filename.endswith(suffix):
|
|
||||||
# If default filetype (None), considered as restructuredtext.
|
|
||||||
return filetype or 'restructuredtext'
|
|
||||||
else:
|
|
||||||
raise FiletypeNotFoundError
|
|
||||||
|
|
||||||
|
|
||||||
def read_doc(app, env, filename):
|
def read_doc(app, env, filename):
|
||||||
# type: (Sphinx, BuildEnvironment, str) -> nodes.document
|
# type: (Sphinx, BuildEnvironment, str) -> nodes.document
|
||||||
"""Parse a document and convert to doctree."""
|
"""Parse a document and convert to doctree."""
|
||||||
@ -349,3 +338,11 @@ def read_doc(app, env, filename):
|
|||||||
|
|
||||||
pub.publish()
|
pub.publish()
|
||||||
return pub.document
|
return pub.document
|
||||||
|
|
||||||
|
|
||||||
|
deprecated_alias('sphinx.io',
|
||||||
|
{
|
||||||
|
'FiletypeNotFoundError': FiletypeNotFoundError,
|
||||||
|
'get_filetype': get_filetype,
|
||||||
|
},
|
||||||
|
RemovedInSphinx40Warning)
|
||||||
|
@ -22,7 +22,7 @@ from sphinx.config import Config
|
|||||||
from sphinx.domains.std import make_glossary_term, split_term_classifiers
|
from sphinx.domains.std import make_glossary_term, split_term_classifiers
|
||||||
from sphinx.locale import __, init as init_locale
|
from sphinx.locale import __, init as init_locale
|
||||||
from sphinx.transforms import SphinxTransform
|
from sphinx.transforms import SphinxTransform
|
||||||
from sphinx.util import split_index_msg, logging
|
from sphinx.util import split_index_msg, logging, get_filetype
|
||||||
from sphinx.util.i18n import docname_to_domain
|
from sphinx.util.i18n import docname_to_domain
|
||||||
from sphinx.util.nodes import (
|
from sphinx.util.nodes import (
|
||||||
LITERAL_TYPE_NODES, IMAGE_TYPE_NODES, NodeMatcher,
|
LITERAL_TYPE_NODES, IMAGE_TYPE_NODES, NodeMatcher,
|
||||||
@ -61,7 +61,8 @@ def publish_msgstr(app: "Sphinx", source: str, source_path: str, source_line: in
|
|||||||
from sphinx.io import SphinxI18nReader
|
from sphinx.io import SphinxI18nReader
|
||||||
reader = SphinxI18nReader()
|
reader = SphinxI18nReader()
|
||||||
reader.setup(app)
|
reader.setup(app)
|
||||||
parser = app.registry.create_source_parser(app, 'restructuredtext')
|
filetype = get_filetype(config.source_suffix, source_path)
|
||||||
|
parser = app.registry.create_source_parser(app, filetype)
|
||||||
doc = reader.read(
|
doc = reader.read(
|
||||||
source=StringInput(source=source,
|
source=StringInput(source=source,
|
||||||
source_path="%s:%s:<translated>" % (source_path, source_line)),
|
source_path="%s:%s:<translated>" % (source_path, source_line)),
|
||||||
|
@ -31,7 +31,9 @@ from urllib.parse import urlsplit, urlunsplit, quote_plus, parse_qsl, urlencode
|
|||||||
from docutils.utils import relative_path
|
from docutils.utils import relative_path
|
||||||
|
|
||||||
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
|
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
|
||||||
from sphinx.errors import PycodeError, SphinxParallelError, ExtensionError
|
from sphinx.errors import (
|
||||||
|
PycodeError, SphinxParallelError, ExtensionError, FiletypeNotFoundError
|
||||||
|
)
|
||||||
from sphinx.locale import __
|
from sphinx.locale import __
|
||||||
from sphinx.util import logging
|
from sphinx.util import logging
|
||||||
from sphinx.util.console import strip_colors, colorize, bold, term_width_line # type: ignore
|
from sphinx.util.console import strip_colors, colorize, bold, term_width_line # type: ignore
|
||||||
@ -120,6 +122,16 @@ def get_matching_docs(dirname: str, suffixes: List[str],
|
|||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
def get_filetype(source_suffix, filename):
|
||||||
|
# type: (Dict[str, str], str) -> str
|
||||||
|
for suffix, filetype in source_suffix.items():
|
||||||
|
if filename.endswith(suffix):
|
||||||
|
# If default filetype (None), considered as restructuredtext.
|
||||||
|
return filetype or 'restructuredtext'
|
||||||
|
else:
|
||||||
|
raise FiletypeNotFoundError
|
||||||
|
|
||||||
|
|
||||||
class FilenameUniqDict(dict):
|
class FilenameUniqDict(dict):
|
||||||
"""
|
"""
|
||||||
A dictionary that automatically generates unique names for its keys,
|
A dictionary that automatically generates unique names for its keys,
|
||||||
|
Loading…
Reference in New Issue
Block a user