diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 8452ef07..5621e4b7 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -10,3 +10,5 @@ updates: actions: patterns: - "*" + cooldown: + default-days: 7 diff --git a/.github/release.yml b/.github/release.yml index 9d1e0987..5f89818f 100644 --- a/.github/release.yml +++ b/.github/release.yml @@ -1,5 +1,5 @@ changelog: exclude: authors: - - dependabot - - pre-commit-ci + - dependabot[bot] + - pre-commit-ci[bot] diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 88c0c7cb..3a2f8524 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,19 +2,21 @@ name: Lint on: [push, pull_request, workflow_dispatch] +permissions: {} + env: FORCE_COLOR: 1 - -permissions: - contents: read + RUFF_OUTPUT_FORMAT: github jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - uses: actions/checkout@v6 + with: + persist-credentials: false + - uses: actions/setup-python@v6 with: python-version: "3.x" - uses: pre-commit/action@v3.0.1 diff --git a/.github/workflows/pypi-package.yml b/.github/workflows/pypi-package.yml index 744d49bd..885c30bb 100644 --- a/.github/workflows/pypi-package.yml +++ b/.github/workflows/pypi-package.yml @@ -8,8 +8,7 @@ on: - published workflow_dispatch: -permissions: - contents: read +permissions: {} env: FORCE_COLOR: 1 @@ -21,7 +20,16 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 + with: + persist-credentials: false + - uses: actions/setup-python@v6 + + - name: Compile translations + run: | + pip install --upgrade pip + pip install -r requirements.txt + python babel_runner.py compile - uses: hynek/build-and-inspect-python-package@v2 @@ -41,12 +49,10 @@ jobs: steps: - name: Download packages built by build-and-inspect-python-package - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v6 with: name: Packages path: dist - name: Upload package to PyPI uses: pypa/gh-action-pypi-publish@release/v1 - with: - attestations: true diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 23e6c7e6..7b9875e2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,6 +2,8 @@ name: Tests on: [push, pull_request, workflow_dispatch] +permissions: {} + env: FORCE_COLOR: 1 @@ -12,12 +14,17 @@ jobs: strategy: fail-fast: false matrix: - branch: ["3.14", "3.13", "3.12"] + python-version: ["3.15", "3.14", "3.13", "3.12"] + include: + - python-version: "3.15" + branch: "main" steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - uses: actions/checkout@v6 + with: + persist-credentials: false + - uses: actions/setup-python@v6 with: - python-version: ${{ matrix.branch }} + python-version: ${{ matrix.python-version }} allow-prereleases: true cache: pip - name: Clone docsbuild scripts @@ -38,16 +45,16 @@ jobs: --skip-cache-invalidation --theme "$(pwd)" --languages en - --branches ${{ matrix.branch }} - ${{ matrix.branch == '3.14' && '--select-output no-html' || '' }} + --branches ${{ matrix.branch || matrix.python-version }} + ${{ matrix.branch == 'main' && '--select-output no-html' || '' }} - name: Show logs if: failure() run: | cat ./logs/docsbuild.log - name: Upload - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v5 with: - name: doc-html-${{ matrix.branch }} + name: doc-html-${{ matrix.python-version }} path: www/ translations: @@ -59,8 +66,10 @@ jobs: # Test minimum supported and latest stable from 3.x series python-version: ["3.12", "3"] steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - uses: actions/checkout@v6 + with: + persist-credentials: false + - uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} allow-prereleases: true @@ -71,7 +80,7 @@ jobs: pip install -r requirements.txt - name: Remove locale file for testing shell: bash - run: rm -rf locales/pt_BR/ + run: rm -rf python_docs_theme/locale/pt_BR/ - run: python babel_runner.py extract - run: python babel_runner.py init -l pt_BR - run: python babel_runner.py update @@ -80,10 +89,7 @@ jobs: - run: python babel_runner.py compile -l pt_BR - name: Print .pot file shell: bash - run: cat locales/messages.pot + run: cat python_docs_theme/locale/python-docs-theme.pot - name: Print .po file shell: bash - run: cat locales/pt_BR/LC_MESSAGES/messages.po - - name: list files in locales dir - shell: bash - run: ls -R locales/ + run: cat python_docs_theme/locale/pt_BR/LC_MESSAGES/python-docs-theme.po diff --git a/.github/zizmor.yml b/.github/zizmor.yml new file mode 100644 index 00000000..9b42b47c --- /dev/null +++ b/.github/zizmor.yml @@ -0,0 +1,10 @@ +# Configuration for the zizmor static analysis tool, run via pre-commit in CI +# https://woodruffw.github.io/zizmor/configuration/ +rules: + dangerous-triggers: + ignore: + - documentation-links.yml + unpinned-uses: + config: + policies: + "*": ref-pin diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9a7e83b3..af1d14d3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,6 +32,11 @@ repos: hooks: - id: actionlint + - repo: https://github.com/woodruffw/zizmor-pre-commit + rev: v1.17.0 + hooks: + - id: zizmor + - repo: https://github.com/tox-dev/pyproject-fmt rev: v2.5.0 hooks: diff --git a/CHANGELOG.rst b/CHANGELOG.md similarity index 53% rename from CHANGELOG.rst rename to CHANGELOG.md index 07b2735e..069a1149 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.md @@ -1,18 +1,50 @@ -Changelog -========= +# Changelog -`2025.5 `_ ---------------------------------------------------------------------------- +## [2025.12](https://github.com/python/python-docs-theme/releases/tag/2025.12) + +* Add support for green, red and yellow side borders for code examples by @hugovk in https://github.com/python/python-docs-theme/pull/285 +* Add Portuguese translation by @NyaPuma in https://github.com/python/python-docs-theme/pull/281 +* Add support for Python 3.15 by @hugovk in https://github.com/python/python-docs-theme/pull/282 +* Convert CHANGELOG and CONTRIBUTING from .rst to .md by @hugovk in https://github.com/python/python-docs-theme/pull/277 +* Add zizmor to CI and fix findings by @hugovk in https://github.com/python/python-docs-theme/pull/283 + +## [2025.10](https://github.com/python/python-docs-theme/releases/tag/2025.10) + +* Add Romanian translation by @octaG-M in https://github.com/python/python-docs-theme/pull/272 +* Add Arabic and Russian translations by @StanFromIreland in https://github.com/python/python-docs-theme/pull/274 +* Add French translation by @JulienPalard in https://github.com/python/python-docs-theme/pull/275 +* Update authors in `pyproject.toml` by @StanFromIreland in https://github.com/python/python-docs-theme/pull/271 +* Add link to devguide in README by @StanFromIreland in https://github.com/python/python-docs-theme/pull/266 + +## [2025.9.2](https://github.com/python/python-docs-theme/releases/tag/2025.9.2) + +* Add Korean and Indonesian translations from Transifex in https://github.com/python/python-docs-theme/pull/264 +* Add German translation by @cmaureir in https://github.com/python/python-docs-theme/pull/262 +* Fix compilation of translations and loading of translations on pages with html + source in https://github.com/python/python-docs-theme/pull/263 +* Fix search button cutting off long translations in https://github.com/python/python-docs-theme/pull/268 +* Fix `Copy` button copying line numbers by @StanFromIreland in https://github.com/python/python-docs-theme/pull/270 + +## [2025.9.1](https://github.com/python/python-docs-theme/releases/tag/2025.9.1) + +* Add Japanese, Turkish and Spanish translations from Transifex in https://github.com/python/python-docs-theme/pull/259 + +## [2025.9](https://github.com/python/python-docs-theme/releases/tag/2025.9) + +* Enable theme translation and add Polish by @StanFromIreland in https://github.com/python/python-docs-theme/pull/246 +* Add Greek translation by @lysnikolaou and @skpanagiotis in https://github.com/python/python-docs-theme/pull/256 and https://github.com/python/python-docs-theme/pull/257 +* Add Swedish translation by @yeager in https://github.com/python/python-docs-theme/pull/250 +* Add Brazilian Portuguese, Simplified Chinese and Traditional Chinese translations from [Transifex](https://explore.transifex.com/python-doc/python-docs-theme/) in https://github.com/python/python-docs-theme/pull/253 + +## [2025.5](https://github.com/python/python-docs-theme/releases/tag/2025.5) * Make the copy button only appear when hovered over or clicked on by @kevteg in https://github.com/python/python-docs-theme/pull/243 -`2025.4.1 `_ -------------------------------------------------------------------------------- +## [2025.4.1](https://github.com/python/python-docs-theme/releases/tag/2025.4.1) * Fix copy button with multiple tracebacks by @tomasr8 in https://github.com/python/python-docs-theme/pull/240 -`2025.4 `_ ---------------------------------------------------------------------------- +## [2025.4](https://github.com/python/python-docs-theme/releases/tag/2025.4) * Require Sphinx 7.3 by @AA-Turner in https://github.com/python/python-docs-theme/pull/221 * Add support for Python 3.14 by @hugovk https://github.com/python/python-docs-theme/pull/236 @@ -23,8 +55,7 @@ Changelog * Remove self-closing tags by @hugovk in https://github.com/python/python-docs-theme/pull/226 * Replace deprecated classifier with licence expression (PEP 639) by @hugovk in https://github.com/python/python-docs-theme/pull/237 -`2025.2 `_ ---------------------------------------------------------------------------- +## [2025.2](https://github.com/python/python-docs-theme/releases/tag/2025.2) - Note minimum requirements for Sphinx (#216) Contributed by Adam Turner @@ -32,17 +63,15 @@ Changelog Contributed by Tomas Roun - Make sidebar width more flexible (#218) Contributed by Tomas Roun -- Set ``__version__`` in the runtime package (#222) +- Set `__version__` in the runtime package (#222) Contributed by Adam Turner -`2024.12 `_ ------------------------------------------------------------------------------ +## [2024.12](https://github.com/python/python-docs-theme/releases/tag/2024.12) - Hide header and search bar when printing (#204) Contributed by Hugo van Kemenade -`2024.10 `_ ------------------------------------------------------------------------------ +## [2024.10](https://github.com/python/python-docs-theme/releases/tag/2024.10) - Add support for Python 3.13 (#196) Contributed by Hugo van Kemenade @@ -53,60 +82,53 @@ Changelog - Generate digital attestations for PyPI (PEP 740) (#198) Contributed by Hugo van Kemenade -`2024.6 `_ ---------------------------------------------------------------------------- +## [2024.6](https://github.com/python/python-docs-theme/releases/tag/2024.6) - Add backgrounds and borders to admonitions (#190) Contributed by Hugo van Kemenade - Use different colour for 'Return value: Borrowed reference' (#188) Contributed by Hugo van Kemenade -`2024.4 `_ ---------------------------------------------------------------------------- +## [2024.4](https://github.com/python/python-docs-theme/releases/tag/2024.4) - Add colour to version change directives (#185) Contributed by Hugo van Kemenade -- Only show 'Last updated on ...' when ``last_updated`` defined (#183) +- Only show 'Last updated on ...' when `last_updated` defined (#183) Contributed by Hugo van Kemenade - Use system font stack for all code (#186) Contributed by Hugo van Kemenade -`2024.3 `_ ---------------------------------------------------------------------------- +## [2024.3](https://github.com/python/python-docs-theme/releases/tag/2024.3) - Modernise font: use system font stack to improve text readability and webpage performance (#174) Contributed by Hugo van Kemenade - Remove incorrect CSS property (#178) Contributed by Kerim Kabirov -`2024.2 `_ ---------------------------------------------------------------------------- +## [2024.2](https://github.com/python/python-docs-theme/releases/tag/2024.2) - Do not underline navigation links (#169) Contributed by Hugo van Kemenade - Only apply underline offset to code formatting for underline visibility (#171) Contributed by Hugo van Kemenade -`2024.1 `_ ---------------------------------------------------------------------------- +## [2024.1](https://github.com/python/python-docs-theme/releases/tag/2024.1) - Underline links for readability and a11y (#160, #166) Contributed by Hugo van Kemenade -- Add ``hosted_on`` variable for a link in the footer (#165) +- Add `hosted_on` variable for a link in the footer (#165) Contributed by Hugo van Kemenade -- Consistently reference ``theme_root_icon`` (#163) +- Consistently reference `theme_root_icon` (#163) Contributed by Marko Budiselic - Dark mode: fix contrast of footer highlight (#162) Contributed by Hugo van Kemenade -`2023.9 `_ ---------------------------------------------------------------------------- +## [2023.9](https://github.com/python/python-docs-theme/releases/tag/2023.9) - Focus search box when pressing slash (#153) Contributed by Hugo van Kemenade -`2023.8 `_ ---------------------------------------------------------------------------- +## [2023.8](https://github.com/python/python-docs-theme/releases/tag/2023.8) - Add Python 3.12 and 3.13 classifiers (#147) Contributed by Hugo van Kemenade @@ -115,14 +137,13 @@ Changelog - Restore the menu on mobile devices (inadvertently broken in 2023.7) (#146) Contributed by Hugo van Kemenade -`2023.7 `_ ---------------------------------------------------------------------------- +## [2023.7](https://github.com/python/python-docs-theme/releases/tag/2023.7) - Fix compatibility with Sphinx 7.1 (#137) Contributed by Pradyun Gedam - Enable the slash keypress to focus the search field (#141) Contributed by Mike Fiedler -- Sphinx 6.2 fix: add ``nav.contents`` where ``div.topic`` is used (#138) +- Sphinx 6.2 fix: add `nav.contents` where `div.topic` is used (#138) Contributed by Hugo van Kemenade - Dark mode: fix contrast for C++ specific styling (#133) Contributed by Hugo van Kemenade @@ -131,29 +152,26 @@ Changelog - Test with Python 3.12 (#140) Contributed by Hugo van Kemenade -`2023.5 `_ ---------------------------------------------------------------------------- +## [2023.5](https://github.com/python/python-docs-theme/releases/tag/2023.5) - Add a dark theme. (#44) Contributed by Nils K - Fix: Remove searchbox id from form. (fixes #117) Contributed by Nils K -- Update ``python-docs-theme`` to work with Sphinx 5 & 6. (#99 & #127) +- Update `python-docs-theme` to work with Sphinx 5 & 6. (#99 & #127) Contributed by Adam Turner -- Override font for ``.sig`` for consistency with other code blocks. (#121) +- Override font for `.sig` for consistency with other code blocks. (#121) Contributed by Chris Warrick - Dark mode: add class to invert image brightness. (#128) Contributed by Hugo van Kemenade -`2023.3.1 `_ -------------------------------------------------------------------------------- +## [2023.3.1](https://github.com/python/python-docs-theme/releases/tag/2023.3.1) - Skip cache-busting for old Sphinx #113 -`2023.3 `_ ---------------------------------------------------------------------------- +## [2023.3](https://github.com/python/python-docs-theme/releases/tag/2023.3) - Fix problem with monospace rendering in Vivaldi #104 - Fix mobile nav obstructing content #96 @@ -161,30 +179,26 @@ Changelog - Append a hash ?digest to CSS files for cache-busting #108 -`2022.1 `_ ----------------------------------------------------------------------------- +## [2022.1](https://github.com/python/python-docs-theme/releases/tag/2022.1) - Add a configuration for license URL. (#90) - Exclude the floating navbar from CHM help. (#84) - Make sidebar scrollable and sticky (on modern browsers) (#91) -`2021.11.1 `_ ----------------------------------------------------------------------------------- +## [2021.11.1](https://github.com/python/python-docs-theme/releases/tag/2021.11.1) - Fix monospace again, on buggy Google Chrome (#87) Contributed by Tushar Sadhwani -`2021.11 `_ ------------------------------------------------------------------------------- +## [2021.11](https://github.com/python/python-docs-theme/releases/tag/2021.11) - Fix monospace on buggy Google Chrome (#85) Contributed by Tushar Sadhwani -`2021.8 `_ ------------------------------------------------------------------------------ +## [2021.8](https://github.com/python/python-docs-theme/releases/tag/2021.8) - Add the copyright_url variable in the theme (#67) Contributed by jablonskidev @@ -196,8 +210,7 @@ Changelog Contributed by Olga Bulat -`2021.5 `_ ------------------------------------------------------------------------------ +## [2021.5](https://github.com/python/python-docs-theme/releases/tag/2021.5) - Make the theme responsive (#46) Contributed by Olga Bulat. @@ -211,8 +224,7 @@ Changelog Contributed by Julien Palard. -`2020.12 `_ ------------------------------------------------------------------------------- +## [2020.12](https://github.com/python/python-docs-theme/releases/tag/v2020.12) - Updated the readme, to remind user to install the package in a virtual environment. (#41) Contributed by Mariatta. @@ -229,12 +241,10 @@ Changelog - Fixed code bgcolor and codetextcolor for Sphinx 3.1.0+ (#57) Contributed by Zhiming Wang. -2018.7 ------- -Corresponds to `44a8f30 `_ +## 2018.7 +Corresponds to [44a8f30](https://github.com/python/python-docs-theme/commit/44a8f306db9ec86d277a8a687538d5d51e415130) -`2018.2 `_ ---------------------------------------------------------------------------- +## [2018.2](https://github.com/python/python-docs-theme/releases/tag/2018.2) Initial release. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..f26b902a --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,26 @@ +# How to release + +- Update `CHANGELOG.md` +- Bump version (YYYY.MM) in `python_docs_theme/__init__.py` +- Commit +- Push to check tests pass on + [GitHub Actions](https://github.com/python/python-docs-theme/actions) +- Go to https://github.com/python/python-docs-theme/releases +- Click "Draft a new release" +- Click "Choose a tag" +- Type the next YYYY.MM version (no leading zero) and + select "**Create new tag: YYYY.MM** on publish" +- Leave the "Release title" blank (it will be autofilled) +- Click "Generate release notes" and amend as required +- Click "Publish release" +- Check the tagged [GitHub Actions build](https://github.com/python/python-docs-theme/actions/workflows/pypi-package.yml) + has deployed to [PyPI](https://pypi.org/project/python-docs-theme/#history) + +# Makefile usage + +This project includes a simple Makefile for syncing changes to the theme with +the main CPython repository. Run `make help` for details on available rules. + +There is one configurable variable, `CPYTHON_PATH`, which should be the path +to the CPython repository on your machine. By default, it points to +`../cpython`. diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst deleted file mode 100644 index c85b77ca..00000000 --- a/CONTRIBUTING.rst +++ /dev/null @@ -1,28 +0,0 @@ -How to release --------------- - -- Update ``CHANGELOG.rst`` -- Bump version (YYYY.MM) in ``python_docs_theme/__init__.py`` -- Commit -- Push to check tests pass on - `GitHub Actions `__ -- Go to https://github.com/python/python-docs-theme/releases -- Click "Draft a new release" -- Click "Choose a tag" -- Type the next YYYY.MM version (no leading zero) and - select "**Create new tag: YYYY.MM** on publish" -- Leave the "Release title" blank (it will be autofilled) -- Click "Generate release notes" and amend as required -- Click "Publish release" -- Check the tagged `GitHub Actions build `__ - has deployed to `PyPI `__ - -Makefile usage --------------- - -This project includes a simple Makefile for syncing changes to the theme with -the main CPython repository. Run ``make help`` for details on available rules. - -There is one configurable variable, ``CPYTHON_PATH``, which should be the path -to the CPython repository on your machine. By default, it points to -``../cpython``. diff --git a/Makefile b/Makefile index bae89325..dda3c238 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ CPYTHON_PATH = ../cpython PYTHON = python3 PACKAGE_ABS_PATH = $(shell pwd)/$(shell find dist/python-docs-theme-*.tar.gz) +SPHINXOPTS = .PHONY: help @@ -22,7 +23,7 @@ venv: .PHONY: html html: venv cd $(CPYTHON_PATH)/Doc && \ - make html + make SPHINXOPTS="$(SPHINXOPTS)" html .PHONY: htmlview htmlview: html diff --git a/README.md b/README.md index fedd7f76..6d89793a 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,13 @@ To use this theme, add the following to `conf.py`: - `html_sidebars`, defaults taken from https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_sidebars + +## Translation + +This theme supports localization. For more information see the [Python Developer's +Guide](https://devguide.python.org/documentation/translations/translating/#how-do-i-translate-the-python-docs-sphinx-theme). + + ## Preview See a demo of the CPython docs using this theme: diff --git a/babel_runner.py b/babel_runner.py index 0785ae2f..677f6da2 100755 --- a/babel_runner.py +++ b/babel_runner.py @@ -1,5 +1,5 @@ -#!/usr/bin/venv python3 """Script for handling translations with Babel""" + from __future__ import annotations import argparse @@ -8,18 +8,18 @@ import tomllib from pathlib import Path -PROJECT_DIR = Path(__file__).resolve().parent -PYPROJECT_TOML = PROJECT_DIR / "pyproject.toml" -INIT_PY = PROJECT_DIR / "python_docs_theme" / "__init__.py" - # Global variables used by pybabel below (paths relative to PROJECT_DIR) -DOMAIN = "messages" +DOMAIN = "python-docs-theme" COPYRIGHT_HOLDER = "Python Software Foundation" -LOCALES_DIR = "locales" -POT_FILE = Path(LOCALES_DIR, f"{DOMAIN}.pot") SOURCE_DIR = "python_docs_theme" MAPPING_FILE = ".babel.cfg" +PROJECT_DIR = Path(__file__).resolve().parent +PYPROJECT_TOML = Path(PROJECT_DIR, "pyproject.toml") +INIT_PY = PROJECT_DIR / SOURCE_DIR / "__init__.py" +LOCALES_DIR = Path(f"{SOURCE_DIR}", "locale") +POT_FILE = Path(LOCALES_DIR, f"{DOMAIN}.pot") + def get_project_info() -> dict: """Retrieve project's info to populate the message catalog template""" @@ -75,13 +75,24 @@ def init_locale(locale: str) -> None: if pofile.exists(): print(f"There is already a message catalog for locale {locale}, skipping.") return - cmd = ["pybabel", "init", "-i", POT_FILE, "-d", LOCALES_DIR, "-l", locale] + cmd = [ + "pybabel", + "init", + "-i", + POT_FILE, + "-d", + LOCALES_DIR, + "-D", + DOMAIN, + "-l", + locale, + ] subprocess.run(cmd, cwd=PROJECT_DIR, check=True) def update_catalogs(locale: str) -> None: """Update translations from existing message catalogs""" - cmd = ["pybabel", "update", "-i", POT_FILE, "-d", LOCALES_DIR] + cmd = ["pybabel", "update", "-i", POT_FILE, "-d", LOCALES_DIR, "-D", DOMAIN] if locale: cmd.extend(["-l", locale]) subprocess.run(cmd, cwd=PROJECT_DIR, check=True) @@ -89,7 +100,7 @@ def update_catalogs(locale: str) -> None: def compile_catalogs(locale: str) -> None: """Compile existing message catalogs""" - cmd = ["pybabel", "compile", "-d", LOCALES_DIR] + cmd = ["pybabel", "compile", "-d", LOCALES_DIR, "-D", DOMAIN] if locale: cmd.extend(["-l", locale]) subprocess.run(cmd, cwd=PROJECT_DIR, check=True) diff --git a/pyproject.toml b/pyproject.toml index a614351d..b8598f52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ description = "The Sphinx theme for the CPython docs and related projects" readme = "README.md" license = "PSF-2.0" license-files = [ "LICENSE" ] -authors = [ { name = "PyPA", email = "distutils-sig@python.org" } ] +authors = [ { name = "Python Docs Sphinx Theme maintainers" } ] requires-python = ">=3.12" classifiers = [ "Development Status :: 5 - Production/Stable", @@ -22,6 +22,7 @@ classifiers = [ "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", + "Programming Language :: Python :: 3.15", "Topic :: Documentation", "Topic :: Software Development :: Documentation", ] @@ -70,4 +71,4 @@ lint.ignore = [ lint.isort.required-imports = [ "from __future__ import annotations" ] [tool.pyproject-fmt] -max_supported_python = "3.14" +max_supported_python = "3.15" diff --git a/python_docs_theme/__init__.py b/python_docs_theme/__init__.py index 2336dc1e..a6c8f18a 100644 --- a/python_docs_theme/__init__.py +++ b/python_docs_theme/__init__.py @@ -2,20 +2,47 @@ from pathlib import Path +from sphinx.locale import get_translation + TYPE_CHECKING = False if TYPE_CHECKING: + from typing import Any + from sphinx.application import Sphinx from sphinx.util.typing import ExtensionMetadata -__version__ = "2025.5" +__version__ = "2025.12" THEME_PATH = Path(__file__).resolve().parent +LOCALE_DIR = THEME_PATH / "locale" +MESSAGE_CATALOG_NAME = "python-docs-theme" + + +def add_translation_to_context( + app: Sphinx, + pagename: str, + templatename: str, + context: dict[str, Any], + doctree: None, +) -> None: + theme_gettext = get_translation(MESSAGE_CATALOG_NAME) + sphinx_gettext = get_translation("sphinx") + + def combined(message: str) -> str: + translation = theme_gettext(message) + if translation == message: + return sphinx_gettext(message) + return translation + + context["_"] = context["gettext"] = context["ngettext"] = combined def setup(app: Sphinx) -> ExtensionMetadata: app.require_sphinx("7.3") app.add_html_theme("python_docs_theme", str(THEME_PATH)) + app.add_message_catalog(MESSAGE_CATALOG_NAME, LOCALE_DIR) + app.connect("html-page-context", add_translation_to_context) return { "version": __version__, diff --git a/python_docs_theme/layout.html b/python_docs_theme/layout.html index a74517c9..1903fad4 100644 --- a/python_docs_theme/layout.html +++ b/python_docs_theme/layout.html @@ -136,13 +136,13 @@

{{ _('Navigation') }}

{% block footer %}