【问题标题】:Can you rename "table of contents" in the Sphinx sidebar?您可以在 Sphinx 侧边栏中重命名“目录”吗?
【发布时间】:2011-07-26 00:36:51
【问题描述】:

更一般地说,您如何重命名 Sphinx 默认元素(例如,Quick SearchSearch)?可以吗?

【问题讨论】:

    标签: python python-sphinx sidebar


    【解决方案1】:

    您可以通过以下方式通过覆盖模板将“快速搜索”更改为其他内容:

    1. 在 Sphinx 项目目录中创建一个名为 templates 的文件夹。

    2. <Sphinx install dir>/themes/basic/searchbox.html复制到templates

    3. 在conf.py中,添加

      templates_path = ["templates"]
      
    4. searchbox.html 的副本中将“快速搜索”重命名为您想要的任何名称。

    但我不会这样做。

    更灵活的方法是创建一个 gettext MO 文件并按照the documentation for locale_dirs 中的描述设置配置。像这样:

    1. 模板文件<Sphinx install dir>/locale/sphinx.pot 包含所有可以翻译的字符串。将该文件复制到本地 sphinx.po 文件。

    2. 将您的更改添加到sphinx.po

    3. 使用msgfmt.pysphinx.po编译成sphinx.mo

    4. sphinx.mo放到合适的目录下(<your_locale_dir>/en/LC_MESSAGES是英文)。

    另见http://docs.python.org/library/gettext.html#internationalizing-your-programs-and-modules

    【讨论】:

    • “propper”方式的说明不是(或不再)非常精确。无需从安装的默认 .po 文件中复制翻译。您也不需要使用 msgfmt.py 进行编译,只要设置了gettext_auto_build
    【解决方案2】:

    根据 Sphinx 配置documentation,您应该能够修改 html 模板,或者将 Sphinx 指向新模板,以通过处理模板的 html 来实现您想要做的事情。

    当前模板在上下文中提供了搜索标题,我不确定是什么填充了 _('search') 的上下文值。如果您可以尝试通过修改 /sphinx/sphinx/locale/sphinx.pot 中的语言环境文件来自定义它,我会徘徊:

    #: sphinx/themes/agogo/layout.html:49 sphinx/themes/basic/layout.html:137
    #: sphinx/themes/basic/search.html:11 sphinx/themes/basic/search.html:20
    msgid "Search"
    msgstr ""
    

    并说msgstr "My alternative search" 而不是msgstr ""

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    • 2014-05-21
    • 2013-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多