feat: Add comprehensive Chinese localization support for issue #412 (#649)

* feat: Add comprehensive Chinese localization support for issue #412

          - Add locale parameter to ChatRequest model to capture user's language preference
          - Implement language-aware template loading in template.py with fallback to English
          - Update all apply_prompt_template calls to pass locale through the workflow
          - Create Chinese translations for 14 core prompt files:
            * Main agents: coordinator, planner, researcher, reporter, coder
            * Subprocess agents: podcast_script_writer, ppt_composer, prompt_enhancer
            * Writing assistant: all 6 prose prompts
          - Update app.py to extract and propagate locale through workflow state
          - Support both zh-CN and en-US locales with automatic fallback
          - Ensure locale flows through all agent nodes and template rendering

* address the review suggestions
This commit is contained in:
Willem Jiang
2025-10-24 16:31:19 +08:00
committed by GitHub
parent 052490b116
commit 5eada04f50
20 changed files with 1165 additions and 15 deletions

View File

@@ -209,13 +209,13 @@ def planner_node(
"locale": state.get("locale", "en-US"),
"research_topic": state["clarified_question"],
}
messages = apply_prompt_template("planner", clean_state, configurable)
messages = apply_prompt_template("planner", clean_state, configurable, state.get("locale", "en-US"))
logger.info(
f"Clarification mode: Using clarified question: {state['clarified_question']}"
)
else:
# Normal mode: use full conversation history
messages = apply_prompt_template("planner", state, configurable)
messages = apply_prompt_template("planner", state, configurable, state.get("locale", "en-US"))
if state.get("enable_background_investigation") and state.get(
"background_investigation_results"
@@ -357,7 +357,7 @@ def coordinator_node(
# ============================================================
if not enable_clarification:
# Use normal prompt with explicit instruction to skip clarification
messages = apply_prompt_template("coordinator", state)
messages = apply_prompt_template("coordinator", state, locale=state.get("locale", "en-US"))
messages.append(
{
"role": "system",
@@ -410,7 +410,7 @@ def coordinator_node(
# Prepare the messages for the coordinator
state_messages = list(state.get("messages", []))
messages = apply_prompt_template("coordinator", state)
messages = apply_prompt_template("coordinator", state, locale=state.get("locale", "en-US"))
clarification_history = reconstruct_clarification_history(
state_messages, clarification_history, initial_topic
@@ -618,7 +618,7 @@ def reporter_node(state: State, config: RunnableConfig):
],
"locale": state.get("locale", "en-US"),
}
invoke_messages = apply_prompt_template("reporter", input_, configurable)
invoke_messages = apply_prompt_template("reporter", input_, configurable, input_.get("locale", "en-US"))
observations = state.get("observations", [])
# Add a reminder about the new report format, citation style, and table usage