]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
📝 Add banner to translated pages (#14809)
authorMotov Yurii <109919500+YuriiMotov@users.noreply.github.com>
Wed, 4 Feb 2026 13:26:02 +0000 (16:26 +0300)
committerGitHub <noreply@github.com>
Wed, 4 Feb 2026 13:26:02 +0000 (14:26 +0100)
* Add banner to translated pages

* Add link to English version. Use modern syntax for details block

* 🎨 Auto format

* Move `translation-banner.md` inside `docs` directory

* 🎨 Auto format

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
docs/en/docs/translation-banner.md [new file with mode: 0644]
docs/ru/docs/translation-banner.md [new file with mode: 0644]
scripts/mkdocs_hooks.py

diff --git a/docs/en/docs/translation-banner.md b/docs/en/docs/translation-banner.md
new file mode 100644 (file)
index 0000000..1422870
--- /dev/null
@@ -0,0 +1,11 @@
+/// details | 🌐 Translation by AI and humans
+
+This translation was made by AI guided by humans. 🤝
+
+It could have mistakes of misunderstanding the original meaning, or looking unnatural, etc. 🤖
+
+You can improve this translation by [helping us guide the AI LLM better](https://fastapi.tiangolo.com/contributing/#translations).
+
+[English version](ENGLISH_VERSION_URL)
+
+///
diff --git a/docs/ru/docs/translation-banner.md b/docs/ru/docs/translation-banner.md
new file mode 100644 (file)
index 0000000..78ebd67
--- /dev/null
@@ -0,0 +1,11 @@
+/// details | 🌐 Перевод выполнен с помощью ИИ и людей
+
+Этот перевод был сделан ИИ под руководством людей. 🤝
+
+В нем могут быть ошибки из-за неправильного понимания оригинального смысла или неестественности и т. д. 🤖
+
+Вы можете улучшить этот перевод, [помогая нам лучше направлять ИИ LLM](https://fastapi.tiangolo.com/ru/contributing/#translations).
+
+[Английская версия](ENGLISH_VERSION_URL)
+
+///
index 4b781270a2c58a66d0cc496aa7ce84fab2de8f09..567c0111dc8a7258a76f4056598bf7049864a0a5 100644 (file)
@@ -26,6 +26,17 @@ def get_missing_translation_content(docs_dir: str) -> str:
     return missing_translation_path.read_text(encoding="utf-8")
 
 
+@lru_cache
+def get_translation_banner_content(docs_dir: str) -> str:
+    docs_dir_path = Path(docs_dir)
+    translation_banner_path = docs_dir_path / "translation-banner.md"
+    if not translation_banner_path.is_file():
+        translation_banner_path = (
+            docs_dir_path.parent.parent / "en" / "docs" / "translation-banner.md"
+        )
+    return translation_banner_path.read_text(encoding="utf-8")
+
+
 @lru_cache
 def get_mkdocs_material_langs() -> list[str]:
     material_path = Path(material.__file__).parent
@@ -151,4 +162,21 @@ def on_page_markdown(
         if markdown.startswith("#"):
             header, _, body = markdown.partition("\n\n")
         return f"{header}\n\n{missing_translation_content}\n\n{body}"
-    return markdown
+
+    docs_dir_path = Path(config.docs_dir)
+    en_docs_dir_path = docs_dir_path.parent.parent / "en/docs"
+
+    if docs_dir_path == en_docs_dir_path:
+        return markdown
+
+    # For translated pages add translation banner
+    translation_banner_content = get_translation_banner_content(config.docs_dir)
+    en_url = "https://fastapi.tiangolo.com/" + page.url.lstrip("/")
+    translation_banner_content = translation_banner_content.replace(
+        "ENGLISH_VERSION_URL", en_url
+    )
+    header = ""
+    body = markdown
+    if markdown.startswith("#"):
+        header, _, body = markdown.partition("\n\n")
+    return f"{header}\n\n{translation_banner_content}\n\n{body}"