Accept PathLike in Sphinx.add_message_catalog()

This commit is contained in:
Adam Turner
2024-10-25 22:47:15 +01:00
parent 8cd599c50a
commit 116a430cac
4 changed files with 7 additions and 7 deletions

View File

@@ -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/``

View File

@@ -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

View File

@@ -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.

View File

@@ -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.