mirror of https://github.com/tiangolo/fastapi.git
📝 Add banner to translated pages (#14809)
* 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>
This commit is contained in:
parent
9e0f4ca77a
commit
61f95c9606
|
|
@ -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)
|
||||
|
||||
///
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
/// details | 🌐 Перевод выполнен с помощью ИИ и людей
|
||||
|
||||
Этот перевод был сделан ИИ под руководством людей. 🤝
|
||||
|
||||
В нем могут быть ошибки из-за неправильного понимания оригинального смысла или неестественности и т. д. 🤖
|
||||
|
||||
Вы можете улучшить этот перевод, [помогая нам лучше направлять ИИ LLM](https://fastapi.tiangolo.com/ru/contributing/#translations).
|
||||
|
||||
[Английская версия](ENGLISH_VERSION_URL)
|
||||
|
||||
///
|
||||
|
|
@ -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}"
|
||||
|
|
|
|||
Loading…
Reference in New Issue