Skip to content

Commit a6ff414

Browse files
committed
fix(translate_only): fix filename corruption when replacing language suffix
- Only replace language suffix at the END of filename - Prevents "general" from becoming "gzh-TWeral" - Add backwards compatibility for old format filenames
1 parent d0153fe commit a6ff414

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

tools/ai-markmap-agent/translate_only.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ def find_latest_english_output(config: dict) -> Path | None:
5050
if final_path.exists():
5151
return final_path
5252

53+
# Try old format filenames (for backwards compatibility)
54+
old_formats = [
55+
f"{prefix}_general_ai_en.md",
56+
f"{prefix}_specialist_ai_en.md",
57+
f"{prefix}_ontology_ai_en.md",
58+
]
59+
for old_filename in old_formats:
60+
old_path = md_dir / old_filename
61+
if old_path.exists():
62+
print(f" ⚠ Found old format file: {old_filename}")
63+
return old_path
64+
5365
return None
5466

5567

@@ -172,10 +184,12 @@ def main() -> int:
172184
if args.output:
173185
output_path = Path(args.output)
174186
else:
175-
# Replace language in filename
187+
# Replace language suffix in filename (only at the end!)
176188
stem = input_path.stem
177-
if f"_{args.source}" in stem:
178-
new_stem = stem.replace(f"_{args.source}", f"_{args.target}")
189+
suffix = f"_{args.source}"
190+
if stem.endswith(suffix):
191+
# Only replace if it's at the END of the filename
192+
new_stem = stem[:-len(suffix)] + f"_{args.target}"
179193
else:
180194
new_stem = f"{stem}_{args.target}"
181195
output_path = input_path.parent / f"{new_stem}.md"

0 commit comments

Comments
 (0)