Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Commit
  • Loading branch information
StanFromIreland committed Sep 9, 2025
commit 313a83d59b26409ca78d858a625def791134c612
2 changes: 1 addition & 1 deletion babel_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,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, "-D", DOMAIN]
cmd = ["pybabel", "compile", "-d", LOCALES_DIR, "-D", DOMAIN, "--use-fuzzy"]
if locale:
cmd.extend(["-l", locale])
subprocess.run(cmd, cwd=PROJECT_DIR, check=True)
Expand Down
18 changes: 13 additions & 5 deletions python_docs_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@
MESSAGE_CATALOG_NAME = "python-docs-theme"


def add_translation_to_context(app, pagename, templatename, context, doctree):
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
theme_gettext = get_translation(MESSAGE_CATALOG_NAME)
sphinx_gettext = get_translation("sphinx")

def combined(msg):
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
trans = theme_gettext(msg)
if trans == msg:
return sphinx_gettext(msg)
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
return trans
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated

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)

def add_translation_to_context(app, pagename, templatename, context, doctree):
_ = get_translation(MESSAGE_CATALOG_NAME)
Comment thread
StanFromIreland marked this conversation as resolved.
context["_"] = context["gettext"] = context["ngettext"] = _

app.connect("html-page-context", add_translation_to_context)

return {
Expand Down
Loading