Fix one translated document by comparing it to the English version. Returns True if processed successfully, False otherwise.
(path: Path)
| 64 | |
| 65 | |
| 66 | def process_one_page(path: Path) -> bool: |
| 67 | """ |
| 68 | Fix one translated document by comparing it to the English version. |
| 69 | |
| 70 | Returns True if processed successfully, False otherwise. |
| 71 | """ |
| 72 | |
| 73 | try: |
| 74 | lang_code = path.parts[1] |
| 75 | if lang_code == "en": |
| 76 | print(f"Skipping English document: {path}") |
| 77 | return True |
| 78 | |
| 79 | en_doc_path = Path("docs") / "en" / Path(*path.parts[2:]) |
| 80 | |
| 81 | doc_lines = path.read_text(encoding="utf-8").splitlines() |
| 82 | en_doc_lines = en_doc_path.read_text(encoding="utf-8").splitlines() |
| 83 | |
| 84 | doc_lines = check_translation( |
| 85 | doc_lines=doc_lines, |
| 86 | en_doc_lines=en_doc_lines, |
| 87 | lang_code=lang_code, |
| 88 | auto_fix=True, |
| 89 | path=str(path), |
| 90 | ) |
| 91 | |
| 92 | # Write back the fixed document |
| 93 | doc_lines.append("") # Ensure file ends with a newline |
| 94 | path.write_text("\n".join(doc_lines), encoding="utf-8") |
| 95 | |
| 96 | except ValueError as e: |
| 97 | print(f"Error processing {path}: {e}") |
| 98 | return False |
| 99 | return True |
| 100 | |
| 101 | |
| 102 | @cli.command() |
no test coverage detected