Translate index.md too

This commit is contained in:
sublimegame
2025-04-16 16:15:29 +07:00
committed by GitHub
parent c387aef52d
commit 5e16ee74a8

View File

@@ -486,7 +486,7 @@ class WriteChapters(BatchNode):
# Add language instruction if not English
language_instruction = ""
if language.lower() != "english":
language_instruction = f"Write this tutorial chapter in {language}. Ensure all explanations, examples, and comments are in {language}.\n\n"
language_instruction = f"IMPORTANT: Write this ENTIRE tutorial chapter in {language} language. You MUST translate ALL content including explanations, examples, code comments, and technical terms into {language}. DO NOT use English anywhere except in code syntax and proper nouns. The entire output should be in {language} only.\n\n"
prompt = f"""
{language_instruction}
@@ -599,17 +599,49 @@ class CombineTutorial(Node):
# --- End Mermaid ---
# Prepare index.md content
index_content = f"# Tutorial: {project_name}\n\n"
index_content += f"{relationships_data['summary']}\n\n"
index_content += f"**Source Repository:** [{repo_url}]({repo_url})\n\n"
# Get language from shared store, default to English
language = shared.get("language", "english")
# Add Mermaid diagram for relationships
index_content += "```mermaid\n"
index_content += mermaid_diagram + "\n"
index_content += "```\n\n"
# Prepare index.md content with language-specific titles
if language.lower() != "english":
# For non-English languages, translate the content using LLM
index_content += "## Chapters\n\n"
# 1. Translate the title
title_prompt = f"Translate only the word 'Tutorial' to {language} language. Respond with just the translated word, nothing else."
translated_title = call_llm(title_prompt).strip()
index_content = f"# {translated_title}: {project_name}\n\n"
# 2. Translate the relationship summary
summary_prompt = f"Translate the following text to {language} language:\n\n{relationships_data['summary']}"
translated_summary = call_llm(summary_prompt)
index_content += f"{translated_summary}\n\n"
# 3. Translate "Source Repository"
repo_prompt = f"Translate only the phrase 'Source Repository' to {language} language. Respond with just the translated phrase, nothing else."
translated_repo = call_llm(repo_prompt).strip()
index_content += f"**{translated_repo}:** [{repo_url}]({repo_url})\n\n"
# Add Mermaid diagram for relationships
index_content += "```mermaid\n"
index_content += mermaid_diagram + "\n"
index_content += "```\n\n"
# 4. Translate "Chapters"
chapters_prompt = f"Translate only the word 'Chapters' to {language} language. Respond with just the translated word, nothing else."
translated_chapters = call_llm(chapters_prompt).strip()
index_content += f"## {translated_chapters}\n\n"
else:
# Original English content
index_content = f"# Tutorial: {project_name}\n\n"
index_content += f"{relationships_data['summary']}\n\n"
index_content += f"**Source Repository:** [{repo_url}]({repo_url})\n\n"
# Add Mermaid diagram for relationships
index_content += "```mermaid\n"
index_content += mermaid_diagram + "\n"
index_content += "```\n\n"
index_content += "## Chapters\n\n"
chapter_files = []
# Generate chapter links based on the determined order
@@ -627,15 +659,32 @@ class CombineTutorial(Node):
chapter_content = chapters_content[i]
if not chapter_content.endswith("\n\n"):
chapter_content += "\n\n"
chapter_content += "---\n\nGenerated by [AI Codebase Knowledge Builder](https://github.com/The-Pocket/Tutorial-Codebase-Knowledge)"
# Add attribution with language-specific text
if language.lower() != "english":
# Translate "Generated by" to the target language
gen_prompt = f"Translate only the phrase 'Generated by' to {language} language. Respond with just the translated phrase, nothing else."
translated_gen = call_llm(gen_prompt).strip()
chapter_content += f"---\n\n{translated_gen} [AI Codebase Knowledge Builder](https://github.com/The-Pocket/Tutorial-Codebase-Knowledge)"
else:
chapter_content += "---\n\nGenerated by [AI Codebase Knowledge Builder](https://github.com/The-Pocket/Tutorial-Codebase-Knowledge)"
# Store filename and corresponding content
chapter_files.append({"filename": filename, "content": chapter_content})
else:
print(f"Warning: Mismatch between chapter order, abstractions, or content at index {i} (abstraction index {abstraction_index}). Skipping file generation for this entry.")
# Add attribution to index content
index_content += "\n\n---\n\nGenerated by [AI Codebase Knowledge Builder](https://github.com/The-Pocket/Tutorial-Codebase-Knowledge)"
# Add attribution to index content with language-specific text
if language.lower() != "english":
# We already have the translated "Generated by" phrase from above, reuse it
# If not available (which shouldn't happen), translate it again
if 'translated_gen' not in locals():
gen_prompt = f"Translate only the phrase 'Generated by' to {language} language. Respond with just the translated phrase, nothing else."
translated_gen = call_llm(gen_prompt).strip()
index_content += f"\n\n---\n\n{translated_gen} [AI Codebase Knowledge Builder](https://github.com/The-Pocket/Tutorial-Codebase-Knowledge)"
else:
index_content += "\n\n---\n\nGenerated by [AI Codebase Knowledge Builder](https://github.com/The-Pocket/Tutorial-Codebase-Knowledge)"
return {
"output_path": output_path,