Translate a single file.
(file_path: str, dry_run: bool = False)
| 298 | |
| 299 | |
| 300 | def process_file(file_path: str, dry_run: bool = False): |
| 301 | """Translate a single file.""" |
| 302 | path = KNOWLEDGE_ROOT / file_path |
| 303 | if not path.exists(): |
| 304 | logger.error(f"File not found: {path}") |
| 305 | return |
| 306 | |
| 307 | logger.info(f"Translating: {path.name}") |
| 308 | |
| 309 | if dry_run: |
| 310 | segments = split_into_segments(path.read_text(encoding="utf-8")) |
| 311 | translatable = [s for s in segments if s["translate"]] |
| 312 | total_chars = sum(len(s["text"]) for s in translatable) |
| 313 | logger.info(f" Would translate {len(translatable)} segments, " |
| 314 | f"{total_chars} chars") |
| 315 | return |
| 316 | |
| 317 | en_text = translate_document(path) |
| 318 | if en_text: |
| 319 | en_path = get_en_path(path) |
| 320 | en_path.write_text(en_text, encoding="utf-8") |
| 321 | logger.info(f" Saved: {en_path.name} ({len(en_text)} chars)") |
| 322 | |
| 323 | |
| 324 | def show_stats(): |
no test coverage detected