translate_page() — fastapi Function Reference
Architecture documentation for the translate_page() function in translate.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD fde1dac0_2ec7_f895_3237_c5b8350a5417["translate_page()"] 6dda5e35_b655_8af3_cd89_8c1584a092c4["translate.py"] fde1dac0_2ec7_f895_3237_c5b8350a5417 -->|defined in| 6dda5e35_b655_8af3_cd89_8c1584a092c4 a668556d_47cb_523f_1e1d_60be6b0d8519["translate_lang()"] a668556d_47cb_523f_1e1d_60be6b0d8519 -->|calls| fde1dac0_2ec7_f895_3237_c5b8350a5417 9ce4d449_89b1_9335_4e37_57480b7dc100["update_outdated()"] 9ce4d449_89b1_9335_4e37_57480b7dc100 -->|calls| fde1dac0_2ec7_f895_3237_c5b8350a5417 1197b802_6f25_2a74_88df_75858855484e["add_missing()"] 1197b802_6f25_2a74_88df_75858855484e -->|calls| fde1dac0_2ec7_f895_3237_c5b8350a5417 f52c193a_f0e3_ecf9_398f_43ce6d3d5563["get_langs()"] fde1dac0_2ec7_f895_3237_c5b8350a5417 -->|calls| f52c193a_f0e3_ecf9_398f_43ce6d3d5563 08ab58ed_fb84_c0ad_0e2e_b521607ca3c9["generate_lang_path()"] fde1dac0_2ec7_f895_3237_c5b8350a5417 -->|calls| 08ab58ed_fb84_c0ad_0e2e_b521607ca3c9 63822d7d_03fc_4331_3f93_3026c9c03415["check_translation()"] fde1dac0_2ec7_f895_3237_c5b8350a5417 -->|calls| 63822d7d_03fc_4331_3f93_3026c9c03415 style fde1dac0_2ec7_f895_3237_c5b8350a5417 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
scripts/translate.py lines 61–148
def translate_page(
*,
language: Annotated[str, typer.Option(envvar="LANGUAGE")],
en_path: Annotated[Path, typer.Option(envvar="EN_PATH")],
) -> None:
assert language != "en", (
"`en` is the source language, choose another language as translation target"
)
langs = get_langs()
language_name = langs[language]
lang_path = Path(f"docs/{language}")
lang_path.mkdir(exist_ok=True)
lang_prompt_path = lang_path / "llm-prompt.md"
assert lang_prompt_path.exists(), f"Prompt file not found: {lang_prompt_path}"
lang_prompt_content = lang_prompt_path.read_text(encoding="utf-8")
en_docs_path = Path("docs/en/docs")
assert str(en_path).startswith(str(en_docs_path)), (
f"Path must be inside {en_docs_path}"
)
out_path = generate_lang_path(lang=language, path=en_path)
out_path.parent.mkdir(parents=True, exist_ok=True)
original_content = en_path.read_text(encoding="utf-8")
old_translation: str | None = None
if out_path.exists():
print(f"Found existing translation: {out_path}")
old_translation = out_path.read_text(encoding="utf-8")
print(f"Translating {en_path} to {language} ({language_name})")
agent = Agent("openai:gpt-5")
prompt_segments = [
general_prompt,
lang_prompt_content,
]
if old_translation:
prompt_segments.extend(
[
"There is an existing previous translation for the original English content, that may be outdated.",
"Update the translation only where necessary:",
"- If the original English content has added parts, also add these parts to the translation.",
"- If the original English content has removed parts, also remove them from the translation, unless you were instructed earlier to not do that in specific cases.",
"- If parts of the original English content have changed, also change those parts in the translation.",
"- If the previous translation violates current instructions, update it.",
"- Otherwise, preserve the original translation LINE-BY-LINE, AS-IS.",
"Do not:",
"- rephrase or rewrite correct lines just to improve the style.",
"- add or remove line breaks, unless the original English content changed.",
"- change formatting or whitespace unless absolutely required.",
"Only change what must be changed. The goal is to minimize diffs for easier human review.",
"UNLESS you were instructed earlier to behave different, there MUST NOT be whole sentences or partial sentences in the updated translation, which are not in the original English content, and there MUST NOT be whole sentences or partial sentences in the original English content, which are not in the updated translation. Remember: the updated translation shall be IN SYNC with the original English content.",
"Previous translation:",
f"%%%\n{old_translation}%%%",
]
)
prompt_segments.extend(
[
f"Translate to {language} ({language_name}).",
"Original content:",
f"%%%\n{original_content}%%%",
]
)
prompt = "\n\n".join(prompt_segments)
MAX_ATTEMPTS = 3
for attempt_no in range(1, MAX_ATTEMPTS + 1):
print(f"Running agent for {out_path} (attempt {attempt_no}/{MAX_ATTEMPTS})")
result = agent.run_sync(prompt)
out_content = f"{result.output.strip()}\n"
try:
check_translation(
doc_lines=out_content.splitlines(),
en_doc_lines=original_content.splitlines(),
lang_code=language,
auto_fix=False,
path=str(out_path),
)
break # Exit loop if no errors
except ValueError as e:
print(
f"Translation check failed on attempt {attempt_no}/{MAX_ATTEMPTS}: {e}"
)
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does translate_page() do?
translate_page() is a function in the fastapi codebase, defined in scripts/translate.py.
Where is translate_page() defined?
translate_page() is defined in scripts/translate.py at line 61.
What does translate_page() call?
translate_page() calls 3 function(s): check_translation, generate_lang_path, get_langs.
What calls translate_page()?
translate_page() is called by 3 function(s): add_missing, translate_lang, update_outdated.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free