mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Accept PathLike in Sphinx.add_message_catalog()
This commit is contained in:
@@ -51,8 +51,8 @@ In practice, you have to:
|
||||
:caption: src/__init__.py
|
||||
|
||||
def setup(app):
|
||||
package_dir = path.abspath(path.dirname(__file__))
|
||||
locale_dir = os.path.join(package_dir, 'locales')
|
||||
package_dir = Path(__file__).parent.resolve()
|
||||
locale_dir = package_dir / 'locales'
|
||||
app.add_message_catalog(MESSAGE_CATALOG_NAME, locale_dir)
|
||||
|
||||
#. Generate message catalog template ``*.pot`` file, usually in ``locale/``
|
||||
|
||||
@@ -1616,7 +1616,7 @@ class Sphinx:
|
||||
"""
|
||||
self.registry.add_html_math_renderer(name, inline_renderers, block_renderers)
|
||||
|
||||
def add_message_catalog(self, catalog: str, locale_dir: str) -> None:
|
||||
def add_message_catalog(self, catalog: str, locale_dir: str | os.PathLike[str]) -> None:
|
||||
"""Register a message catalog.
|
||||
|
||||
:param catalog: The name of the catalog
|
||||
|
||||
@@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
import locale
|
||||
import sys
|
||||
from gettext import NullTranslations, translation
|
||||
from os import path
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -141,11 +141,11 @@ def init(
|
||||
return translator, has_translation
|
||||
|
||||
|
||||
_LOCALE_DIR = path.abspath(path.dirname(__file__))
|
||||
_LOCALE_DIR = Path(__file__).parent.resolve()
|
||||
|
||||
|
||||
def init_console(
|
||||
locale_dir: str | None = None,
|
||||
locale_dir: str | os.PathLike[str] | None = None,
|
||||
catalog: str = 'sphinx',
|
||||
) -> tuple[NullTranslations, bool]:
|
||||
"""Initialize locale for console.
|
||||
|
||||
@@ -20,7 +20,7 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
def _init_console(
|
||||
locale_dir: str | None = sphinx.locale._LOCALE_DIR,
|
||||
locale_dir: str | os.PathLike[str] | None = sphinx.locale._LOCALE_DIR,
|
||||
catalog: str = 'sphinx',
|
||||
) -> tuple[gettext.NullTranslations, bool]:
|
||||
"""Monkeypatch ``init_console`` to skip its action.
|
||||
|
||||
Reference in New Issue
Block a user