MCPcopy Create free account
hub / github.com/fastapi/fastapi / process_one_page

Function process_one_page

scripts/translation_fixer.py:66–99  ·  view source on GitHub ↗

Fix one translated document by comparing it to the English version. Returns True if processed successfully, False otherwise.

(path: Path)

Source from the content-addressed store, hash-verified

64
65
66def 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()

Callers 2

fix_allFunction · 0.85
fix_pagesFunction · 0.85

Calls 2

check_translationFunction · 0.90
PathClass · 0.50

Tested by

no test coverage detected