Skip to content

Commit 116a430

Browse files
committed
Accept PathLike in Sphinx.add_message_catalog()
1 parent 8cd599c commit 116a430

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

doc/extdev/i18n.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ In practice, you have to:
5151
:caption: src/__init__.py
5252
5353
def setup(app):
54-
package_dir = path.abspath(path.dirname(__file__))
55-
locale_dir = os.path.join(package_dir, 'locales')
54+
package_dir = Path(__file__).parent.resolve()
55+
locale_dir = package_dir / 'locales'
5656
app.add_message_catalog(MESSAGE_CATALOG_NAME, locale_dir)
5757
5858
#. Generate message catalog template ``*.pot`` file, usually in ``locale/``

sphinx/application.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ def add_html_math_renderer(
16161616
"""
16171617
self.registry.add_html_math_renderer(name, inline_renderers, block_renderers)
16181618

1619-
def add_message_catalog(self, catalog: str, locale_dir: str) -> None:
1619+
def add_message_catalog(self, catalog: str, locale_dir: str | os.PathLike[str]) -> None:
16201620
"""Register a message catalog.
16211621
16221622
:param catalog: The name of the catalog

sphinx/locale/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import locale
66
import sys
77
from gettext import NullTranslations, translation
8-
from os import path
8+
from pathlib import Path
99
from typing import TYPE_CHECKING
1010

1111
if TYPE_CHECKING:
@@ -141,11 +141,11 @@ def init(
141141
return translator, has_translation
142142

143143

144-
_LOCALE_DIR = path.abspath(path.dirname(__file__))
144+
_LOCALE_DIR = Path(__file__).parent.resolve()
145145

146146

147147
def init_console(
148-
locale_dir: str | None = None,
148+
locale_dir: str | os.PathLike[str] | None = None,
149149
catalog: str = 'sphinx',
150150
) -> tuple[NullTranslations, bool]:
151151
"""Initialize locale for console.

tests/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
def _init_console(
23-
locale_dir: str | None = sphinx.locale._LOCALE_DIR,
23+
locale_dir: str | os.PathLike[str] | None = sphinx.locale._LOCALE_DIR,
2424
catalog: str = 'sphinx',
2525
) -> tuple[gettext.NullTranslations, bool]:
2626
"""Monkeypatch ``init_console`` to skip its action.

0 commit comments

Comments
 (0)