Skip to content

Commit 5d2d616

Browse files
authored
Merge pull request #3 from TGreen87/codex/update-translate-docs-py-for-mkdocs-search-plugin
Fix mkdocs search with i18n
2 parents 716e483 + 4b5c3af commit 5d2d616

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

docs/scripts/translate_docs.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
# gpt-4.5 needed this for better quality
1414
ENABLE_SMALL_CHUNK_TRANSLATION = False
1515

16-
SEARCH_EXCLUSION = """---
17-
search:
18-
exclude: true
19-
---
20-
"""
16+
17+
def search_front_matter(lang_code: str) -> str:
18+
return f"---\nsearch:\n lang: {lang_code}\n---\n"
2119

2220

2321
# Define the source and target directories
@@ -239,8 +237,7 @@ def translate_file(file_path: str, target_path: str, lang_code: str) -> None:
239237
for idx, code_block in enumerate(code_blocks):
240238
translated_text = translated_text.replace(f"CODE_BLOCK_{idx:02}", code_block)
241239

242-
# FIXME: enable mkdocs search plugin to seamlessly work with i18n plugin
243-
translated_text = SEARCH_EXCLUSION + translated_text
240+
translated_text = search_front_matter(lang_code) + translated_text
244241
# Save the combined translated content
245242
with open(target_path, "w", encoding="utf-8") as f:
246243
f.write(translated_text)

0 commit comments

Comments
 (0)