MCPcopy Create free account
hub / github.com/openai/openai-agents-python / main

Function main

docs/scripts/translate_docs.py:459–526  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

457
458
459def main():
460 parser = argparse.ArgumentParser(description="Translate documentation files")
461 parser.add_argument(
462 "--file",
463 action="append",
464 type=str,
465 help="Specific file to translate (relative to docs directory).",
466 )
467 parser.add_argument(
468 "--file-list",
469 type=str,
470 help="Path to a newline-delimited file list to translate.",
471 )
472 parser.add_argument(
473 "--mode",
474 choices=["only-changes", "full"],
475 default="only-changes",
476 help="Translation mode. 'only-changes' translates only when the Japanese file is older than the English source.",
477 )
478 args = parser.parse_args()
479
480 check_translation_outdated = args.mode == "only-changes"
481
482 if args.file or args.file_list:
483 file_args: list[str] = []
484 if args.file:
485 file_args.extend(args.file)
486 if args.file_list:
487 with open(args.file_list, encoding="utf-8") as f:
488 file_args.extend([line.strip() for line in f.read().splitlines() if line.strip()])
489 file_paths: list[str] = []
490 for file_arg in file_args:
491 relative_file = normalize_source_file_arg(file_arg)
492 file_path = os.path.join(source_dir, relative_file)
493 if os.path.exists(file_path):
494 file_paths.append(file_path)
495 else:
496 print(f"Warning: File {file_path} does not exist; skipping.")
497 if not file_paths:
498 print("Error: No valid files found to translate")
499 sys.exit(1)
500 translate_source_files(file_paths, check_translation_outdated=check_translation_outdated)
501 print("Translation completed for requested file(s)")
502 else:
503 # Traverse the source directory (original behavior)
504 for root, _, file_names in os.walk(source_dir):
505 # Skip the target directories
506 if any(lang in root for lang in languages):
507 continue
508 # Increasing this will make the translation faster; you can decide considering the model's capacity
509 concurrency = 6
510 with ThreadPoolExecutor(max_workers=concurrency) as executor:
511 futures = []
512 for file_name in file_names:
513 filepath = os.path.join(root, file_name)
514 futures.append(
515 executor.submit(
516 translate_single_source_file,

Callers 1

translate_docs.pyFile · 0.70

Calls 7

translate_source_filesFunction · 0.85
appendMethod · 0.80
resultMethod · 0.80
clearMethod · 0.80
readMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected