Skip to content

Commit 313a83d

Browse files
Commit
1 parent 413eb45 commit 313a83d

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

babel_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def update_catalogs(locale: str) -> None:
100100

101101
def compile_catalogs(locale: str) -> None:
102102
"""Compile existing message catalogs"""
103-
cmd = ["pybabel", "compile", "-d", LOCALES_DIR, "-D", DOMAIN]
103+
cmd = ["pybabel", "compile", "-d", LOCALES_DIR, "-D", DOMAIN, "--use-fuzzy"]
104104
if locale:
105105
cmd.extend(["-l", locale])
106106
subprocess.run(cmd, cwd=PROJECT_DIR, check=True)

python_docs_theme/__init__.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,24 @@
1616
MESSAGE_CATALOG_NAME = "python-docs-theme"
1717

1818

19+
def add_translation_to_context(app, pagename, templatename, context, doctree):
20+
theme_gettext = get_translation(MESSAGE_CATALOG_NAME)
21+
sphinx_gettext = get_translation("sphinx")
22+
23+
def combined(msg):
24+
trans = theme_gettext(msg)
25+
if trans == msg:
26+
return sphinx_gettext(msg)
27+
return trans
28+
29+
context["_"] = context["gettext"] = context["ngettext"] = combined
30+
31+
1932
def setup(app: Sphinx) -> ExtensionMetadata:
2033
app.require_sphinx("7.3")
2134

2235
app.add_html_theme("python_docs_theme", str(THEME_PATH))
2336
app.add_message_catalog(MESSAGE_CATALOG_NAME, LOCALE_DIR)
24-
25-
def add_translation_to_context(app, pagename, templatename, context, doctree):
26-
_ = get_translation(MESSAGE_CATALOG_NAME)
27-
context["_"] = context["gettext"] = context["ngettext"] = _
28-
2937
app.connect("html-page-context", add_translation_to_context)
3038

3139
return {

0 commit comments

Comments
 (0)