Skip to content

Commit 54a746f

Browse files
committed
fix: correct filename generation for translated outputs
Fix language code replacement in translation phase to only replace the language suffix, not all occurrences of the language code string. This prevents incorrect filenames like "neetcode_gzh-TWeral_ai_zh-TW" when translating from "general_en" to "general_zh-TW". - Use rsplit("_", 1) to parse output_key format correctly - Only replace language code at the end of the key - Improve html_converter.py parsing logic for robustness
1 parent 896b9d9 commit 54a746f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

tools/ai-markmap-agent/src/graph.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,18 @@ def run_translations(state: WorkflowState) -> WorkflowState:
392392
)
393393

394394
for output_key, content in writer_outputs.items():
395-
if source_lang in output_key:
396-
target_key = output_key.replace(source_lang, target_lang)
395+
# Parse output_key format: "{type}_{lang}" (e.g., "general_en")
396+
parts = output_key.rsplit("_", 1)
397+
if len(parts) == 2 and parts[1] == source_lang:
398+
target_key = f"{parts[0]}_{target_lang}"
399+
elif source_lang in output_key:
400+
# Fallback: only replace if it's at the end of the string
401+
if output_key.endswith(f"_{source_lang}"):
402+
target_key = output_key[:-len(f"_{source_lang}")] + f"_{target_lang}"
403+
else:
404+
continue # Skip if source_lang appears but not at the end
405+
else:
406+
continue # Skip if source_lang not found
397407

398408
try:
399409
if debug.enabled:

tools/ai-markmap-agent/src/output/html_converter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ def save_all_outputs(
248248

249249
for output_key, content in results.items():
250250
# Parse output key (e.g., "general_en" or "specialist_zh-TW")
251-
parts = output_key.split("_", 1)
251+
# Use rsplit to handle language codes that might contain underscores
252+
parts = output_key.rsplit("_", 1)
252253
if len(parts) == 2:
253254
output_type, lang = parts
254255
else:

0 commit comments

Comments
 (0)