mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge branch '3.x' into 7410_suppress_circular_toctree_warning
This commit is contained in:
commit
bbd673e253
1
CHANGES
1
CHANGES
@ -13,6 +13,7 @@ Deprecated
|
|||||||
Features added
|
Features added
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
* LaTeX: Make the ``toplevel_sectioning`` setting optional in LaTeX theme
|
||||||
* #7410: Allow to suppress "circular toctree references detected" warnings using
|
* #7410: Allow to suppress "circular toctree references detected" warnings using
|
||||||
:confval:`suppress_warnings`
|
:confval:`suppress_warnings`
|
||||||
|
|
||||||
|
@ -35,25 +35,25 @@ In practice, you have to:
|
|||||||
:func:`sphinx.locale.get_translation` function, usually renamed ``_()``,
|
:func:`sphinx.locale.get_translation` function, usually renamed ``_()``,
|
||||||
e.g.:
|
e.g.:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
:caption: src/__init__.py
|
:caption: src/__init__.py
|
||||||
|
|
||||||
from sphinx.locale import get_translation
|
from sphinx.locale import get_translation
|
||||||
|
|
||||||
MESSAGE_CATALOG_NAME = 'myextension'
|
MESSAGE_CATALOG_NAME = 'myextension'
|
||||||
_ = get_translation(MESSAGE_CATALOG_NAME)
|
_ = get_translation(MESSAGE_CATALOG_NAME)
|
||||||
|
|
||||||
translated_text = _('Hello Sphinx!')
|
translated_text = _('Hello Sphinx!')
|
||||||
|
|
||||||
#. Set up your extension to be aware of its dedicated translations:
|
#. Set up your extension to be aware of its dedicated translations:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
:caption: src/__init__.py
|
:caption: src/__init__.py
|
||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
package_dir = path.abspath(path.dirname(__file__))
|
package_dir = path.abspath(path.dirname(__file__))
|
||||||
locale_dir = os.path.join(package_dir, 'locales')
|
locale_dir = os.path.join(package_dir, 'locales')
|
||||||
app.add_message_catalog(MESSAGE_CATALOG_NAME, locale_dir)
|
app.add_message_catalog(MESSAGE_CATALOG_NAME, locale_dir)
|
||||||
|
|
||||||
#. Generate message catalog template ``*.pot`` file, usually in ``locale/``
|
#. Generate message catalog template ``*.pot`` file, usually in ``locale/``
|
||||||
source directory, for example via `Babel`_:
|
source directory, for example via `Babel`_:
|
||||||
|
@ -66,19 +66,29 @@ class BuiltInTheme(Theme):
|
|||||||
class UserTheme(Theme):
|
class UserTheme(Theme):
|
||||||
"""A user defined LaTeX theme."""
|
"""A user defined LaTeX theme."""
|
||||||
|
|
||||||
|
REQUIRED_CONFIG_KEYS = ['docclass', 'wrapperclass']
|
||||||
|
OPTIONAL_CONFIG_KEYS = ['toplevel_sectioning']
|
||||||
|
|
||||||
def __init__(self, name: str, filename: str) -> None:
|
def __init__(self, name: str, filename: str) -> None:
|
||||||
self.name = name
|
super().__init__(name)
|
||||||
self.config = configparser.RawConfigParser()
|
self.config = configparser.RawConfigParser()
|
||||||
self.config.read(path.join(filename))
|
self.config.read(path.join(filename))
|
||||||
|
|
||||||
try:
|
for key in self.REQUIRED_CONFIG_KEYS:
|
||||||
self.docclass = self.config.get('theme', 'docclass')
|
try:
|
||||||
self.wrapperclass = self.config.get('theme', 'wrapperclass')
|
value = self.config.get('theme', key)
|
||||||
self.toplevel_sectioning = self.config.get('theme', 'toplevel_sectioning')
|
setattr(self, key, value)
|
||||||
except configparser.NoSectionError:
|
except configparser.NoSectionError:
|
||||||
raise ThemeError(__('%r doesn\'t have "theme" setting') % filename)
|
raise ThemeError(__('%r doesn\'t have "theme" setting') % filename)
|
||||||
except configparser.NoOptionError as exc:
|
except configparser.NoOptionError as exc:
|
||||||
raise ThemeError(__('%r doesn\'t have "%s" setting') % (filename, exc.args[0]))
|
raise ThemeError(__('%r doesn\'t have "%s" setting') % (filename, exc.args[0]))
|
||||||
|
|
||||||
|
for key in self.OPTIONAL_CONFIG_KEYS:
|
||||||
|
try:
|
||||||
|
value = self.config.get('theme', key)
|
||||||
|
setattr(self, key, value)
|
||||||
|
except configparser.NoOptionError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ThemeFactory:
|
class ThemeFactory:
|
||||||
|
Loading…
Reference in New Issue
Block a user