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.
- tlate/__init__.py +8 -0
- tlate/__main__.py +3 -0
- tlate/checkpoint.py +155 -0
- tlate/cli.py +1358 -0
- tlate/compare.py +126 -0
- tlate/errors.py +71 -0
- tlate/formats/__init__.py +67 -0
- tlate/formats/androidxml.py +162 -0
- tlate/formats/base.py +100 -0
- tlate/formats/epub.py +136 -0
- tlate/formats/html.py +180 -0
- tlate/formats/jsonfmt.py +196 -0
- tlate/formats/markdown.py +242 -0
- tlate/formats/ooxml.py +681 -0
- tlate/formats/pdf.py +148 -0
- tlate/formats/plaintext.py +136 -0
- tlate/formats/po.py +202 -0
- tlate/formats/subtitles.py +276 -0
- tlate/formats/textdoc.py +131 -0
- tlate/formats/yamlfmt.py +100 -0
- tlate/glossary.py +124 -0
- tlate/images.py +478 -0
- tlate/kit_data/AGENTS.md +129 -0
- tlate/kit_data/CLAUDE.md +3 -0
- tlate/kit_data/GEMINI.md +4 -0
- tlate/kit_data/dot_cursor/rules/tlate.mdc +7 -0
- tlate/kit_data/dot_github/copilot-instructions.md +4 -0
- tlate/kit_data/skills/tlate/SKILL.md +209 -0
- tlate/kit_data/skills/tlate/assets/glossary-template.md +23 -0
- tlate/kit_data/skills/tlate/references/layout-by-format.md +144 -0
- tlate/kit_data/skills/tlate/references/qa-checklist.md +45 -0
- tlate/kit_data/skills/tlate/references/style-guides/default.md +27 -0
- tlate/languages.py +561 -0
- tlate/languages_data/ar/glossary-template.md +23 -0
- tlate/languages_data/ar/pack.json +92 -0
- tlate/languages_data/ar/style-guide.md +18 -0
- tlate/languages_data/de/glossary-template.md +23 -0
- tlate/languages_data/de/pack.json +105 -0
- tlate/languages_data/de/style-guide.md +23 -0
- tlate/languages_data/en/glossary-template.md +23 -0
- tlate/languages_data/en/pack.json +162 -0
- tlate/languages_data/en/style-guide.md +25 -0
- tlate/languages_data/es/glossary-template.md +23 -0
- tlate/languages_data/es/pack.json +110 -0
- tlate/languages_data/es/style-guide.md +25 -0
- tlate/languages_data/fa/glossary-template.md +23 -0
- tlate/languages_data/fa/pack.json +87 -0
- tlate/languages_data/fa/style-guide.md +28 -0
- tlate/languages_data/fr/glossary-template.md +23 -0
- tlate/languages_data/fr/pack.json +107 -0
- tlate/languages_data/fr/style-guide.md +25 -0
- tlate/languages_data/he/glossary-template.md +23 -0
- tlate/languages_data/he/pack.json +87 -0
- tlate/languages_data/he/style-guide.md +28 -0
- tlate/languages_data/hi/glossary-template.md +23 -0
- tlate/languages_data/hi/pack.json +81 -0
- tlate/languages_data/hi/style-guide.md +25 -0
- tlate/languages_data/id/glossary-template.md +23 -0
- tlate/languages_data/id/pack.json +115 -0
- tlate/languages_data/id/style-guide.md +45 -0
- tlate/languages_data/it/glossary-template.md +23 -0
- tlate/languages_data/it/pack.json +97 -0
- tlate/languages_data/it/style-guide.md +25 -0
- tlate/languages_data/ja/glossary-template.md +23 -0
- tlate/languages_data/ja/pack.json +84 -0
- tlate/languages_data/ja/style-guide.md +23 -0
- tlate/languages_data/ko/glossary-template.md +23 -0
- tlate/languages_data/ko/pack.json +84 -0
- tlate/languages_data/ko/style-guide.md +25 -0
- tlate/languages_data/nl/glossary-template.md +23 -0
- tlate/languages_data/nl/pack.json +95 -0
- tlate/languages_data/nl/style-guide.md +25 -0
- tlate/languages_data/pl/glossary-template.md +23 -0
- tlate/languages_data/pl/pack.json +91 -0
- tlate/languages_data/pl/style-guide.md +25 -0
- tlate/languages_data/pt/glossary-template.md +23 -0
- tlate/languages_data/pt/pack.json +106 -0
- tlate/languages_data/pt/style-guide.md +25 -0
- tlate/languages_data/pt-BR/glossary-template.md +23 -0
- tlate/languages_data/pt-BR/pack.json +106 -0
- tlate/languages_data/pt-BR/style-guide.md +25 -0
- tlate/languages_data/ru/glossary-template.md +23 -0
- tlate/languages_data/ru/pack.json +106 -0
- tlate/languages_data/ru/style-guide.md +25 -0
- tlate/languages_data/th/glossary-template.md +23 -0
- tlate/languages_data/th/pack.json +66 -0
- tlate/languages_data/th/style-guide.md +28 -0
- tlate/languages_data/tr/glossary-template.md +23 -0
- tlate/languages_data/tr/pack.json +91 -0
- tlate/languages_data/tr/style-guide.md +25 -0
- tlate/languages_data/ur/glossary-template.md +23 -0
- tlate/languages_data/ur/pack.json +87 -0
- tlate/languages_data/ur/style-guide.md +28 -0
- tlate/languages_data/vi/glossary-template.md +23 -0
- tlate/languages_data/vi/pack.json +95 -0
- tlate/languages_data/vi/style-guide.md +25 -0
- tlate/languages_data/zh/glossary-template.md +23 -0
- tlate/languages_data/zh/pack.json +84 -0
- tlate/languages_data/zh/style-guide.md +28 -0
- tlate/languages_data/zh-Hans/glossary-template.md +23 -0
- tlate/languages_data/zh-Hans/pack.json +84 -0
- tlate/languages_data/zh-Hans/style-guide.md +28 -0
- tlate/languages_data/zh-Hant/glossary-template.md +23 -0
- tlate/languages_data/zh-Hant/pack.json +84 -0
- tlate/languages_data/zh-Hant/style-guide.md +28 -0
- tlate/limits.py +198 -0
- tlate/memory.py +530 -0
- tlate/ocr/__init__.py +28 -0
- tlate/ocr/engines.py +496 -0
- tlate/ocr/pipeline.py +520 -0
- tlate/ocr/render.py +294 -0
- tlate/ocr/types.py +40 -0
- tlate/pdf/__init__.py +137 -0
- tlate/pdf/fonts.py +244 -0
- tlate/pdf/layout.py +309 -0
- tlate/pdf/metrics.py +801 -0
- tlate/pdf/pymupdf_engine.py +1053 -0
- tlate/pipeline.py +438 -0
- tlate/protect.py +243 -0
- tlate/protection.py +1030 -0
- tlate/qa.py +833 -0
- tlate/safety.py +212 -0
- tlate/segments.py +257 -0
- tlate/setup_ws.py +64 -0
- tlate/skip_rules.py +222 -0
- tlate-0.1.0.dist-info/METADATA +172 -0
- tlate-0.1.0.dist-info/RECORD +132 -0
- tlate-0.1.0.dist-info/WHEEL +5 -0
- tlate-0.1.0.dist-info/entry_points.txt +2 -0
- tlate-0.1.0.dist-info/licenses/LICENSE +21 -0
- tlate-0.1.0.dist-info/licenses/THIRD_PARTY_NOTICES.md +85 -0
- 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
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
|