Skip to content

Commit 5e16ee7

Browse files
authored
Translate index.md too
1 parent c387aef commit 5e16ee7

File tree

1 file changed

+62
-13
lines changed

1 file changed

+62
-13
lines changed

nodes.py

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ def exec(self, item):
486486
# Add language instruction if not English
487487
language_instruction = ""
488488
if language.lower() != "english":
489-
language_instruction = f"Write this tutorial chapter in {language}. Ensure all explanations, examples, and comments are in {language}.\n\n"
489+
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"
490490

491491
prompt = f"""
492492
{language_instruction}
@@ -599,17 +599,49 @@ def prep(self, shared):
599599
# --- End Mermaid ---
600600

601601

602-
# Prepare index.md content
603-
index_content = f"# Tutorial: {project_name}\n\n"
604-
index_content += f"{relationships_data['summary']}\n\n"
605-
index_content += f"**Source Repository:** [{repo_url}]({repo_url})\n\n"
602+
# Get language from shared store, default to English
603+
language = shared.get("language", "english")
606604

607-
# Add Mermaid diagram for relationships
608-
index_content += "```mermaid\n"
609-
index_content += mermaid_diagram + "\n"
610-
index_content += "```\n\n"
605+
# Prepare index.md content with language-specific titles
606+
if language.lower() != "english":
607+
# For non-English languages, translate the content using LLM
608+
609+
# 1. Translate the title
610+
title_prompt = f"Translate only the word 'Tutorial' to {language} language. Respond with just the translated word, nothing else."
611+
translated_title = call_llm(title_prompt).strip()
612+
index_content = f"# {translated_title}: {project_name}\n\n"
613+
614+
# 2. Translate the relationship summary
615+
summary_prompt = f"Translate the following text to {language} language:\n\n{relationships_data['summary']}"
616+
translated_summary = call_llm(summary_prompt)
617+
index_content += f"{translated_summary}\n\n"
618+
619+
# 3. Translate "Source Repository"
620+
repo_prompt = f"Translate only the phrase 'Source Repository' to {language} language. Respond with just the translated phrase, nothing else."
621+
translated_repo = call_llm(repo_prompt).strip()
622+
index_content += f"**{translated_repo}:** [{repo_url}]({repo_url})\n\n"
623+
624+
# Add Mermaid diagram for relationships
625+
index_content += "```mermaid\n"
626+
index_content += mermaid_diagram + "\n"
627+
index_content += "```\n\n"
628+
629+
# 4. Translate "Chapters"
630+
chapters_prompt = f"Translate only the word 'Chapters' to {language} language. Respond with just the translated word, nothing else."
631+
translated_chapters = call_llm(chapters_prompt).strip()
632+
index_content += f"## {translated_chapters}\n\n"
633+
else:
634+
# Original English content
635+
index_content = f"# Tutorial: {project_name}\n\n"
636+
index_content += f"{relationships_data['summary']}\n\n"
637+
index_content += f"**Source Repository:** [{repo_url}]({repo_url})\n\n"
611638

612-
index_content += "## Chapters\n\n"
639+
# Add Mermaid diagram for relationships
640+
index_content += "```mermaid\n"
641+
index_content += mermaid_diagram + "\n"
642+
index_content += "```\n\n"
643+
644+
index_content += "## Chapters\n\n"
613645

614646
chapter_files = []
615647
# Generate chapter links based on the determined order
@@ -627,15 +659,32 @@ def prep(self, shared):
627659
chapter_content = chapters_content[i]
628660
if not chapter_content.endswith("\n\n"):
629661
chapter_content += "\n\n"
630-
chapter_content += "---\n\nGenerated by [AI Codebase Knowledge Builder](https://github.com/The-Pocket/Tutorial-Codebase-Knowledge)"
662+
663+
# Add attribution with language-specific text
664+
if language.lower() != "english":
665+
# Translate "Generated by" to the target language
666+
gen_prompt = f"Translate only the phrase 'Generated by' to {language} language. Respond with just the translated phrase, nothing else."
667+
translated_gen = call_llm(gen_prompt).strip()
668+
chapter_content += f"---\n\n{translated_gen} [AI Codebase Knowledge Builder](https://github.com/The-Pocket/Tutorial-Codebase-Knowledge)"
669+
else:
670+
chapter_content += "---\n\nGenerated by [AI Codebase Knowledge Builder](https://github.com/The-Pocket/Tutorial-Codebase-Knowledge)"
631671

632672
# Store filename and corresponding content
633673
chapter_files.append({"filename": filename, "content": chapter_content})
634674
else:
635675
print(f"Warning: Mismatch between chapter order, abstractions, or content at index {i} (abstraction index {abstraction_index}). Skipping file generation for this entry.")
636676

637-
# Add attribution to index content
638-
index_content += "\n\n---\n\nGenerated by [AI Codebase Knowledge Builder](https://github.com/The-Pocket/Tutorial-Codebase-Knowledge)"
677+
# Add attribution to index content with language-specific text
678+
if language.lower() != "english":
679+
# We already have the translated "Generated by" phrase from above, reuse it
680+
# If not available (which shouldn't happen), translate it again
681+
if 'translated_gen' not in locals():
682+
gen_prompt = f"Translate only the phrase 'Generated by' to {language} language. Respond with just the translated phrase, nothing else."
683+
translated_gen = call_llm(gen_prompt).strip()
684+
685+
index_content += f"\n\n---\n\n{translated_gen} [AI Codebase Knowledge Builder](https://github.com/The-Pocket/Tutorial-Codebase-Knowledge)"
686+
else:
687+
index_content += "\n\n---\n\nGenerated by [AI Codebase Knowledge Builder](https://github.com/The-Pocket/Tutorial-Codebase-Knowledge)"
639688

640689
return {
641690
"output_path": output_path,

0 commit comments

Comments
 (0)