MCPcopy Create free account
hub / github.com/RASAAS/docmcp-knowledge / process_file

Function process_file

scripts/translate_fulltext.py:300–321  ·  view source on GitHub ↗

Translate a single file.

(file_path: str, dry_run: bool = False)

Source from the content-addressed store, hash-verified

298
299
300def 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
324def show_stats():

Callers 1

mainFunction · 0.70

Calls 3

split_into_segmentsFunction · 0.85
translate_documentFunction · 0.85
get_en_pathFunction · 0.85

Tested by

no test coverage detected