tlate 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. tlate/__init__.py +8 -0
  2. tlate/__main__.py +3 -0
  3. tlate/checkpoint.py +155 -0
  4. tlate/cli.py +1358 -0
  5. tlate/compare.py +126 -0
  6. tlate/errors.py +71 -0
  7. tlate/formats/__init__.py +67 -0
  8. tlate/formats/androidxml.py +162 -0
  9. tlate/formats/base.py +100 -0
  10. tlate/formats/epub.py +136 -0
  11. tlate/formats/html.py +180 -0
  12. tlate/formats/jsonfmt.py +196 -0
  13. tlate/formats/markdown.py +242 -0
  14. tlate/formats/ooxml.py +681 -0
  15. tlate/formats/pdf.py +148 -0
  16. tlate/formats/plaintext.py +136 -0
  17. tlate/formats/po.py +202 -0
  18. tlate/formats/subtitles.py +276 -0
  19. tlate/formats/textdoc.py +131 -0
  20. tlate/formats/yamlfmt.py +100 -0
  21. tlate/glossary.py +124 -0
  22. tlate/images.py +478 -0
  23. tlate/kit_data/AGENTS.md +129 -0
  24. tlate/kit_data/CLAUDE.md +3 -0
  25. tlate/kit_data/GEMINI.md +4 -0
  26. tlate/kit_data/dot_cursor/rules/tlate.mdc +7 -0
  27. tlate/kit_data/dot_github/copilot-instructions.md +4 -0
  28. tlate/kit_data/skills/tlate/SKILL.md +209 -0
  29. tlate/kit_data/skills/tlate/assets/glossary-template.md +23 -0
  30. tlate/kit_data/skills/tlate/references/layout-by-format.md +144 -0
  31. tlate/kit_data/skills/tlate/references/qa-checklist.md +45 -0
  32. tlate/kit_data/skills/tlate/references/style-guides/default.md +27 -0
  33. tlate/languages.py +561 -0
  34. tlate/languages_data/ar/glossary-template.md +23 -0
  35. tlate/languages_data/ar/pack.json +92 -0
  36. tlate/languages_data/ar/style-guide.md +18 -0
  37. tlate/languages_data/de/glossary-template.md +23 -0
  38. tlate/languages_data/de/pack.json +105 -0
  39. tlate/languages_data/de/style-guide.md +23 -0
  40. tlate/languages_data/en/glossary-template.md +23 -0
  41. tlate/languages_data/en/pack.json +162 -0
  42. tlate/languages_data/en/style-guide.md +25 -0
  43. tlate/languages_data/es/glossary-template.md +23 -0
  44. tlate/languages_data/es/pack.json +110 -0
  45. tlate/languages_data/es/style-guide.md +25 -0
  46. tlate/languages_data/fa/glossary-template.md +23 -0
  47. tlate/languages_data/fa/pack.json +87 -0
  48. tlate/languages_data/fa/style-guide.md +28 -0
  49. tlate/languages_data/fr/glossary-template.md +23 -0
  50. tlate/languages_data/fr/pack.json +107 -0
  51. tlate/languages_data/fr/style-guide.md +25 -0
  52. tlate/languages_data/he/glossary-template.md +23 -0
  53. tlate/languages_data/he/pack.json +87 -0
  54. tlate/languages_data/he/style-guide.md +28 -0
  55. tlate/languages_data/hi/glossary-template.md +23 -0
  56. tlate/languages_data/hi/pack.json +81 -0
  57. tlate/languages_data/hi/style-guide.md +25 -0
  58. tlate/languages_data/id/glossary-template.md +23 -0
  59. tlate/languages_data/id/pack.json +115 -0
  60. tlate/languages_data/id/style-guide.md +45 -0
  61. tlate/languages_data/it/glossary-template.md +23 -0
  62. tlate/languages_data/it/pack.json +97 -0
  63. tlate/languages_data/it/style-guide.md +25 -0
  64. tlate/languages_data/ja/glossary-template.md +23 -0
  65. tlate/languages_data/ja/pack.json +84 -0
  66. tlate/languages_data/ja/style-guide.md +23 -0
  67. tlate/languages_data/ko/glossary-template.md +23 -0
  68. tlate/languages_data/ko/pack.json +84 -0
  69. tlate/languages_data/ko/style-guide.md +25 -0
  70. tlate/languages_data/nl/glossary-template.md +23 -0
  71. tlate/languages_data/nl/pack.json +95 -0
  72. tlate/languages_data/nl/style-guide.md +25 -0
  73. tlate/languages_data/pl/glossary-template.md +23 -0
  74. tlate/languages_data/pl/pack.json +91 -0
  75. tlate/languages_data/pl/style-guide.md +25 -0
  76. tlate/languages_data/pt/glossary-template.md +23 -0
  77. tlate/languages_data/pt/pack.json +106 -0
  78. tlate/languages_data/pt/style-guide.md +25 -0
  79. tlate/languages_data/pt-BR/glossary-template.md +23 -0
  80. tlate/languages_data/pt-BR/pack.json +106 -0
  81. tlate/languages_data/pt-BR/style-guide.md +25 -0
  82. tlate/languages_data/ru/glossary-template.md +23 -0
  83. tlate/languages_data/ru/pack.json +106 -0
  84. tlate/languages_data/ru/style-guide.md +25 -0
  85. tlate/languages_data/th/glossary-template.md +23 -0
  86. tlate/languages_data/th/pack.json +66 -0
  87. tlate/languages_data/th/style-guide.md +28 -0
  88. tlate/languages_data/tr/glossary-template.md +23 -0
  89. tlate/languages_data/tr/pack.json +91 -0
  90. tlate/languages_data/tr/style-guide.md +25 -0
  91. tlate/languages_data/ur/glossary-template.md +23 -0
  92. tlate/languages_data/ur/pack.json +87 -0
  93. tlate/languages_data/ur/style-guide.md +28 -0
  94. tlate/languages_data/vi/glossary-template.md +23 -0
  95. tlate/languages_data/vi/pack.json +95 -0
  96. tlate/languages_data/vi/style-guide.md +25 -0
  97. tlate/languages_data/zh/glossary-template.md +23 -0
  98. tlate/languages_data/zh/pack.json +84 -0
  99. tlate/languages_data/zh/style-guide.md +28 -0
  100. tlate/languages_data/zh-Hans/glossary-template.md +23 -0
  101. tlate/languages_data/zh-Hans/pack.json +84 -0
  102. tlate/languages_data/zh-Hans/style-guide.md +28 -0
  103. tlate/languages_data/zh-Hant/glossary-template.md +23 -0
  104. tlate/languages_data/zh-Hant/pack.json +84 -0
  105. tlate/languages_data/zh-Hant/style-guide.md +28 -0
  106. tlate/limits.py +198 -0
  107. tlate/memory.py +530 -0
  108. tlate/ocr/__init__.py +28 -0
  109. tlate/ocr/engines.py +496 -0
  110. tlate/ocr/pipeline.py +520 -0
  111. tlate/ocr/render.py +294 -0
  112. tlate/ocr/types.py +40 -0
  113. tlate/pdf/__init__.py +137 -0
  114. tlate/pdf/fonts.py +244 -0
  115. tlate/pdf/layout.py +309 -0
  116. tlate/pdf/metrics.py +801 -0
  117. tlate/pdf/pymupdf_engine.py +1053 -0
  118. tlate/pipeline.py +438 -0
  119. tlate/protect.py +243 -0
  120. tlate/protection.py +1030 -0
  121. tlate/qa.py +833 -0
  122. tlate/safety.py +212 -0
  123. tlate/segments.py +257 -0
  124. tlate/setup_ws.py +64 -0
  125. tlate/skip_rules.py +222 -0
  126. tlate-0.1.0.dist-info/METADATA +172 -0
  127. tlate-0.1.0.dist-info/RECORD +132 -0
  128. tlate-0.1.0.dist-info/WHEEL +5 -0
  129. tlate-0.1.0.dist-info/entry_points.txt +2 -0
  130. tlate-0.1.0.dist-info/licenses/LICENSE +21 -0
  131. tlate-0.1.0.dist-info/licenses/THIRD_PARTY_NOTICES.md +85 -0
  132. tlate-0.1.0.dist-info/top_level.txt +1 -0
tlate/__init__.py ADDED
@@ -0,0 +1,8 @@
1
+ """tlate: deterministic document plumbing for multi-language AI translation.
2
+
3
+ The model only translates text segments; this package extracts segments, protects
4
+ placeholders, re-applies translations into the original format, and checks safety
5
+ invariants (never overwrite, SHA-256 verification, refuse encrypted inputs).
6
+ """
7
+
8
+ __version__ = "0.1.0"
tlate/__main__.py ADDED
@@ -0,0 +1,3 @@
1
+ from tlate.cli import main
2
+
3
+ raise SystemExit(main())
tlate/checkpoint.py ADDED
@@ -0,0 +1,155 @@
1
+ """Append-only extraction checkpoints and per-segment state logs (Phase P3b)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import time
7
+ from collections.abc import Iterable
8
+ from pathlib import Path
9
+
10
+ from tlate.errors import SafetyError, ValidationError
11
+ from tlate.safety import append_jsonl
12
+ from tlate.segments import Segment
13
+
14
+ SEGMENT_STATES = frozenset({"pending", "done", "flagged", "skip"})
15
+
16
+
17
+ class SegmentStateLog:
18
+ """Append-only JSONL tracking per-segment lifecycle state (pending/done/flagged/skip)."""
19
+
20
+ def __init__(self, path: Path) -> None:
21
+ self.path = Path(path)
22
+
23
+ def record(self, segment_id: str, state: str, *, reason: str | None = None) -> None:
24
+ if state not in SEGMENT_STATES:
25
+ raise ValidationError(f"invalid segment state {state!r}; expected one of {sorted(SEGMENT_STATES)}")
26
+ append_jsonl(
27
+ self.path,
28
+ {
29
+ "id": str(segment_id),
30
+ "state": state,
31
+ "ts": time.strftime("%Y-%m-%dT%H:%M:%S"),
32
+ "reason": reason,
33
+ },
34
+ )
35
+
36
+ def record_many(self, entries: Iterable[tuple[str, str, str | None]]) -> None:
37
+ for segment_id, state, reason in entries:
38
+ self.record(segment_id, state, reason=reason)
39
+
40
+ def latest_states(self) -> dict[str, dict]:
41
+ """Return the latest logged state record per segment id."""
42
+ if not self.path.is_file():
43
+ return {}
44
+ states: dict[str, dict] = {}
45
+ for n, line in enumerate(self.path.read_text(encoding="utf-8").splitlines(), 1):
46
+ if not line.strip():
47
+ continue
48
+ try:
49
+ rec = json.loads(line)
50
+ except json.JSONDecodeError as exc:
51
+ raise ValidationError(f"{self.path}:{n}: invalid JSON ({exc.msg})") from exc
52
+ if isinstance(rec, dict) and "id" in rec:
53
+ states[str(rec["id"])] = rec
54
+ return states
55
+
56
+
57
+ class ExtractCheckpoint:
58
+ """Append-only JSONL checkpoint enabling resumable ``extract`` and ``ocr`` runs."""
59
+
60
+ def __init__(self, path: Path) -> None:
61
+ self.path = Path(path)
62
+
63
+ def write_header(
64
+ self,
65
+ *,
66
+ source_sha256: str,
67
+ fmt: str,
68
+ source_lang: str,
69
+ target_lang: str,
70
+ ) -> None:
71
+ append_jsonl(
72
+ self.path,
73
+ {
74
+ "kind": "header",
75
+ "source_sha256": source_sha256,
76
+ "format": fmt,
77
+ "source_lang": source_lang,
78
+ "target_lang": target_lang,
79
+ "ts": time.strftime("%Y-%m-%dT%H:%M:%S"),
80
+ },
81
+ )
82
+
83
+ def record_unit(
84
+ self,
85
+ unit: str | int,
86
+ segments: Iterable[Segment | dict],
87
+ *,
88
+ unit_meta: dict | None = None,
89
+ ) -> None:
90
+ serialized = [json.loads(s.to_json()) if isinstance(s, Segment) else dict(s) for s in segments]
91
+ rec: dict = {
92
+ "kind": "unit",
93
+ "unit": str(unit),
94
+ "segments": serialized,
95
+ }
96
+ if unit_meta is not None:
97
+ rec["meta"] = unit_meta
98
+ append_jsonl(self.path, rec)
99
+
100
+ def load(
101
+ self,
102
+ *,
103
+ expected_sha256: str,
104
+ expected_format: str | None = None,
105
+ ) -> tuple[dict | None, dict[str, dict]]:
106
+ """Load and validate checkpoint records against ``expected_sha256``.
107
+
108
+ Returns ``(header, units_by_key)`` where each value in ``units_by_key`` is
109
+ ``{"segments": [...], "meta": {...} | None}``.
110
+ Raises ``SafetyError`` if the checkpoint belongs to a different source SHA-256 or format.
111
+ """
112
+ if not self.path.is_file():
113
+ return None, {}
114
+
115
+ lines = self.path.read_text(encoding="utf-8").splitlines()
116
+ header: dict | None = None
117
+ units: dict[str, dict] = {}
118
+
119
+ for idx, line in enumerate(lines, 1):
120
+ if not line.strip():
121
+ continue
122
+ try:
123
+ rec = json.loads(line)
124
+ except json.JSONDecodeError as exc:
125
+ if idx == len(lines):
126
+ # Tolerate an incomplete trailing line from an interrupted write.
127
+ break
128
+ raise ValidationError(f"{self.path}:{idx}: invalid checkpoint JSON ({exc.msg})") from exc
129
+
130
+ kind = rec.get("kind")
131
+ if kind == "header":
132
+ ckpt_sha = rec.get("source_sha256")
133
+ if ckpt_sha != expected_sha256:
134
+ raise SafetyError(
135
+ f"checkpoint {self.path.name} source_sha256 ({ckpt_sha}) does not match "
136
+ f"source file ({expected_sha256}); refusing to reuse stale checkpoint"
137
+ )
138
+ if expected_format is not None and rec.get("format") != expected_format:
139
+ raise SafetyError(
140
+ f"checkpoint {self.path.name} format ({rec.get('format')!r}) does not match "
141
+ f"expected format ({expected_format!r})"
142
+ )
143
+ header = rec
144
+ elif kind == "unit":
145
+ if header is None:
146
+ raise SafetyError(
147
+ f"checkpoint {self.path.name} has unit record before validated header; refusing"
148
+ )
149
+ unit_key = str(rec.get("unit", ""))
150
+ units[unit_key] = {
151
+ "segments": list(rec.get("segments") or []),
152
+ "meta": rec.get("meta"),
153
+ }
154
+
155
+ return header, units