-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslate_cli.py
More file actions
88 lines (63 loc) · 2.87 KB
/
Copy pathtranslate_cli.py
File metadata and controls
88 lines (63 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import sys
from core.cli_errors import CliError, format_cli_error
from core.task_cli import apply_provider_environment_from_args
from tasks import check_translations, extract_terms, extract_terms_local, revise_translations, translate
def build_parser() -> argparse.ArgumentParser:
"""Build the unified top-level parser and register task subcommands."""
parser = argparse.ArgumentParser(
description="Unified CLI for translation, term extraction, QA, and revision."
)
subparsers = parser.add_subparsers(dest="command", required=True)
translate_parser = translate.configure_parser(
subparsers.add_parser("translate", help="Translate localization files")
)
translate_parser.set_defaults(handler=run_translate)
extract_parser = extract_terms.configure_parser(
subparsers.add_parser("extract-terms", help="Extract glossary terms")
)
extract_parser.set_defaults(handler=run_extract_terms)
extract_local_parser = extract_terms_local.configure_parser(
subparsers.add_parser("extract-terms-local", help="Run local term discovery and PO handoff conversion")
)
extract_local_parser.set_defaults(handler=run_extract_terms_local)
check_parser = check_translations.configure_parser(
subparsers.add_parser("check", help="Check translated files")
)
check_parser.set_defaults(handler=run_check)
revise_parser = revise_translations.configure_parser(
subparsers.add_parser("revise", help="Revise translated files")
)
revise_parser.set_defaults(handler=run_revise)
return parser
def run_translate(args: argparse.Namespace) -> None:
"""Dispatch the `translate` subcommand."""
translate.run_from_args(args)
def run_extract_terms(args: argparse.Namespace) -> None:
"""Dispatch the `extract-terms` subcommand."""
extract_terms.run_from_args(args)
def run_extract_terms_local(args: argparse.Namespace) -> None:
"""Dispatch the `extract-terms-local` subcommand."""
extract_terms_local.run_from_args(args)
def run_check(args: argparse.Namespace) -> None:
"""Dispatch the `check` subcommand."""
check_translations.run_from_args(args)
def run_revise(args: argparse.Namespace) -> None:
"""Dispatch the `revise` subcommand."""
revise_translations.run_from_args(args)
def main(argv: list[str] | None = None) -> None:
"""Parse the command line, apply shared env overrides, and run the handler."""
parser = build_parser()
args = parser.parse_args(argv)
apply_provider_environment_from_args(args)
handler = getattr(args, "handler", None)
if handler is None:
parser.error(f"Unknown command: {args.command}")
try:
handler(args)
except CliError as exc:
raise SystemExit(format_cli_error(exc)) from exc
if __name__ == "__main__":
main(sys.argv[1:])