mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #8026 from tk0miya/7768_docpath_for_figure_language_filename
Close #7768: i18n: figure_language_filename supports {docpath} token
This commit is contained in:
commit
0cfb433b25
1
CHANGES
1
CHANGES
@ -33,6 +33,7 @@ Features added
|
||||
* #7902: html theme: Add a new option :confval:`globaltoc_maxdepth` to control
|
||||
the behavior of globaltoc in sidebar
|
||||
* #7840: i18n: Optimize the dependencies check on bootstrap
|
||||
* #7768: i18n: :confval:`figure_language_filename` supports ``docpath`` token
|
||||
* #5208: linkcheck: Support checks for local links
|
||||
* #5090: setuptools: Link verbosity to distutils' -v and -q option
|
||||
* #7052: add ``:noindexentry:`` to the Python, C, C++, and Javascript domains.
|
||||
|
@ -821,6 +821,8 @@ documentation on :ref:`intl` for details.
|
||||
extension, e.g. ``dirname/filename``
|
||||
* ``{path}`` - the directory path component of the filename, with a trailing
|
||||
slash if non-empty, e.g. ``dirname/``
|
||||
* ``{docpath}`` - the directory path component for the current document, with
|
||||
a trailing slash if non-empty.
|
||||
* ``{basename}`` - the filename without the directory path or file extension
|
||||
components, e.g. ``filename``
|
||||
* ``{ext}`` - the file extension, e.g. ``.png``
|
||||
@ -834,6 +836,9 @@ documentation on :ref:`intl` for details.
|
||||
.. versionchanged:: 1.5
|
||||
Added ``{path}`` and ``{basename}`` tokens.
|
||||
|
||||
.. versionchanged:: 3.2
|
||||
Added ``{docpath}`` token.
|
||||
|
||||
|
||||
.. _math-options:
|
||||
|
||||
|
@ -306,8 +306,12 @@ def get_image_filename_for_language(filename: str, env: "BuildEnvironment") -> s
|
||||
dirname = path.dirname(d['root'])
|
||||
if dirname and not dirname.endswith(path.sep):
|
||||
dirname += path.sep
|
||||
docpath = path.dirname(env.docname)
|
||||
if docpath and not docpath.endswith(path.sep):
|
||||
docpath += path.sep
|
||||
d['path'] = dirname
|
||||
d['basename'] = path.basename(d['root'])
|
||||
d['docpath'] = docpath
|
||||
d['language'] = env.config.language
|
||||
try:
|
||||
return filename_format.format(**d)
|
||||
|
@ -90,6 +90,8 @@ def test_format_date():
|
||||
|
||||
@pytest.mark.xfail(os.name != 'posix', reason="Path separators don't match on windows")
|
||||
def test_get_filename_for_language(app):
|
||||
app.env.temp_data['docname'] = 'index'
|
||||
|
||||
# language is None
|
||||
app.env.config.language = None
|
||||
assert app.env.config.language is None
|
||||
@ -145,6 +147,17 @@ def test_get_filename_for_language(app):
|
||||
with pytest.raises(SphinxError):
|
||||
i18n.get_image_filename_for_language('foo.png', app.env)
|
||||
|
||||
# docpath (for a document in the top of source directory)
|
||||
app.env.config.language = 'en'
|
||||
app.env.config.figure_language_filename = '/{docpath}{language}/{basename}{ext}'
|
||||
assert (i18n.get_image_filename_for_language('foo.png', app.env) ==
|
||||
'/en/foo.png')
|
||||
|
||||
# docpath (for a document in the sub directory)
|
||||
app.env.temp_data['docname'] = 'subdir/index'
|
||||
assert (i18n.get_image_filename_for_language('foo.png', app.env) ==
|
||||
'/subdir/en/foo.png')
|
||||
|
||||
|
||||
def test_CatalogRepository(tempdir):
|
||||
(tempdir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs()
|
||||
|
Loading…
Reference in New Issue
Block a user