开发者

Can you rename "table of contents" in the Sphinx sidebar?

开发者 https://www.devze.com 2023-03-22 17:05 出处:网络
More generally how do you rename Sphinx开发者_运维问答 default elements (e.g. Quick Search to Search)? Can you?Here is how you could change \"Quick search\" to something else by overriding a template:

More generally how do you rename Sphinx开发者_运维问答 default elements (e.g. Quick Search to Search)? Can you?


Here is how you could change "Quick search" to something else by overriding a template:

  1. Create a folder called templates in the Sphinx project directory.

  2. Copy <Sphinx install dir>/themes/basic/searchbox.html to templates.

  3. In conf.py, add

    templates_path = ["templates"]
    
  4. Rename 'Quick search' to whatever you want in the copy of searchbox.html.

But I would not do it this way.

A more flexible approach is to create a gettext MO file and set up the configuration as described in the documentation for locale_dirs. Like this:

  1. The template file <Sphinx install dir>/locale/sphinx.pot contains all the strings that can be translated. Copy that file to a local sphinx.po file.

  2. Add your changes to sphinx.po.

  3. Use msgfmt.py to compile sphinx.po into sphinx.mo.

  4. Put sphinx.mo in the proper directory (<your_locale_dir>/en/LC_MESSAGES for English).

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


According to Sphinx config documentation, you should be able to amend the html templates or perhaps point Sphinx to new templates to achieve what you trying to do by working on the templates' html.

Current templates have search title provided in the context, I am not sure though what populates context value for _('search'). I wander if you could try customizing it by amending the locale file in /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 ""

and say msgstr "My alternative search" instead of msgstr "".

0

精彩评论

暂无评论...
验证码 换一张
取 消