Sphinx: AttributeError: module 'sphinx.util' has no attribute 'i18n'

问题描述 投票:0回答:0

我正在尝试扩展核心方法,

get_image_filename_for_language
在 Sphinx 中。

在运行

sphinx-intl update -p build/gettext -l ja
,我得到错误:

File "conf.py", line 107, in <module>
    sphinx_original_get_image_filename_for_language = sphinx.util.i18n.get_image_filename_for_language
AttributeError: module 'sphinx.util' has no attribute 'i18n'

conf.py:

locale_dirs = ['locale/']   # path is example but recommended.
gettext_compact = False     # optional.
gettext_additional_targets = ['image'] # allows images to be translatable
figure_language_filename = "{root}.{language}{ext}"

sphinx_original_get_image_filename_for_language = sphinx.util.i18n.get_image_filename_for_language
logging.info(sphinx_original_get_image_filename_for_language)

def custom_get_image_filename_for_language(filename, env):
    """
    Hack the absolute path returned by Sphinx based on `figure_language_filename`
    to insert our `../images` relative path to docs-l10n's images folder,
    which mirrors the folder structure of the docs repository.
    The returned string should also be absolute so that `os.path.exists` can properly
    resolve it when trying to concatenate with the original doc folder.
    """
    path = sphinx_original_get_image_filename_for_language(filename, env)
    path = os.path.abspath(os.path.join("./images/", os.path.relpath(path, cwd)))
    logging.info('This is an info message')
    logging.info(path)
    return path

sphinx.util.i18n.get_image_filename_for_language = custom_get_image_filename_for_language

试图扩展 Sphinx 中的核心方法,但出现以下错误

python sphinx
© www.soinside.com 2019 - 2024. All rights reserved.