mirror of
https://github.com/aljazceru/Tutorial-Codebase-Knowledge.git
synced 2026-02-02 13:14:27 +01:00
Translate index.md too
This commit is contained in:
75
nodes.py
75
nodes.py
@@ -486,7 +486,7 @@ class WriteChapters(BatchNode):
|
|||||||
# Add language instruction if not English
|
# Add language instruction if not English
|
||||||
language_instruction = ""
|
language_instruction = ""
|
||||||
if language.lower() != "english":
|
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"""
|
prompt = f"""
|
||||||
{language_instruction}
|
{language_instruction}
|
||||||
@@ -599,17 +599,49 @@ class CombineTutorial(Node):
|
|||||||
# --- End Mermaid ---
|
# --- End Mermaid ---
|
||||||
|
|
||||||
|
|
||||||
# Prepare index.md content
|
# Get language from shared store, default to English
|
||||||
index_content = f"# Tutorial: {project_name}\n\n"
|
language = shared.get("language", "english")
|
||||||
index_content += f"{relationships_data['summary']}\n\n"
|
|
||||||
index_content += f"**Source Repository:** [{repo_url}]({repo_url})\n\n"
|
|
||||||
|
|
||||||
# Add Mermaid diagram for relationships
|
# Prepare index.md content with language-specific titles
|
||||||
index_content += "```mermaid\n"
|
if language.lower() != "english":
|
||||||
index_content += mermaid_diagram + "\n"
|
# For non-English languages, translate the content using LLM
|
||||||
index_content += "```\n\n"
|
|
||||||
|
|
||||||
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 = []
|
chapter_files = []
|
||||||
# Generate chapter links based on the determined order
|
# Generate chapter links based on the determined order
|
||||||
@@ -627,15 +659,32 @@ class CombineTutorial(Node):
|
|||||||
chapter_content = chapters_content[i]
|
chapter_content = chapters_content[i]
|
||||||
if not chapter_content.endswith("\n\n"):
|
if not chapter_content.endswith("\n\n"):
|
||||||
chapter_content += "\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
|
# Store filename and corresponding content
|
||||||
chapter_files.append({"filename": filename, "content": chapter_content})
|
chapter_files.append({"filename": filename, "content": chapter_content})
|
||||||
else:
|
else:
|
||||||
print(f"Warning: Mismatch between chapter order, abstractions, or content at index {i} (abstraction index {abstraction_index}). Skipping file generation for this entry.")
|
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
|
# Add attribution to index content with language-specific text
|
||||||
index_content += "\n\n---\n\nGenerated by [AI Codebase Knowledge Builder](https://github.com/The-Pocket/Tutorial-Codebase-Knowledge)"
|
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 {
|
return {
|
||||||
"output_path": output_path,
|
"output_path": output_path,
|
||||||
|
|||||||
Reference in New Issue
Block a user