feat(review,teams): review foundation — segments, side-by-side editor, rebuild, XLIFF, team workspaces
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 2m14s
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 2m14s
Foundations:
- TranslationSegment model + migration f7e8d9c0b1a2 (segments, workspaces,
workspace_members, glossaries.workspace_id)
- SegmentRecorder injected into all 4 translators: unique (source,
translation) pairs captured per job and persisted (best-effort)
- set_segment_overrides: human-reviewed translations applied verbatim on
rebuild — top priority over TM and provider, zero API calls
Review API (routes/review_routes.py):
- GET /translations/{id}/segments (owner or job token)
- PATCH /segments/{id} edit/approve — feeds the per-user TM so approved
translations are reused in later jobs
- POST /translations/{id}/rebuild — rebuild document with reviewed text
- GET/POST /translations/{id}/xliff — XLIFF 1.2 export/import (edited
segments export their reviewed text)
Review editor (frontend /dashboard/reviews/[jobId]):
- side-by-side source/translation table, inline edit, approve (single or
all), rebuild & download (auth blob), XLIFF export/import, 13 locales
- 'Relire et corriger' link on the translation-complete screen
Team workspaces (routes/workspace_routes.py + /dashboard/teams):
- Workspace/WorkspaceMember models, roles owner/admin/member
- create (Business plan), list with seat usage, invite by email with
seat-limit enforcement (Business=5, Enterprise unlimited), removal
- shared glossaries: workspace members can use a glossary shared to their
workspace (access check extended)
Tests: 1184 passed / 0 failed (11 new: recorder, overrides, docx
capture->rebuild e2e, XLIFF structure/escaping, seats, workspace CRUD,
shared glossary access)
This commit is contained in:
@@ -125,6 +125,18 @@ class ExcelTranslator:
|
||||
user_id, prompt or getattr(self, "_custom_prompt", None)
|
||||
)
|
||||
|
||||
def set_segment_recorder(self, recorder) -> None:
|
||||
"""Attach a segment recorder (review foundation)."""
|
||||
self._segment_recorder = recorder
|
||||
|
||||
def set_segment_overrides(self, overrides) -> None:
|
||||
"""Human-reviewed translations applied verbatim on rebuild."""
|
||||
self._segment_overrides = overrides or {}
|
||||
|
||||
def get_recorded_segments(self):
|
||||
recorder = getattr(self, "_segment_recorder", None)
|
||||
return recorder.get_pairs() if recorder is not None else []
|
||||
|
||||
|
||||
def translate_file(
|
||||
self,
|
||||
@@ -461,12 +473,41 @@ class ExcelTranslator:
|
||||
miss_texts, target_language, source_language
|
||||
)
|
||||
|
||||
# Translation memory: reuse this user's previous translations
|
||||
# (identical context/prompt) before hitting the provider.
|
||||
translated = translate_with_tm(
|
||||
texts, target_language, source_language,
|
||||
provider_name, getattr(self, "_tm_scope", None), _do_translate,
|
||||
from translators.segments import apply_overrides
|
||||
|
||||
# Reviewer overrides (approved/edited segments) win over everything:
|
||||
# no TM lookup, no provider call, zero drift from the reviewed text.
|
||||
ov_hits, ov_misses = apply_overrides(
|
||||
texts, getattr(self, "_segment_overrides", None)
|
||||
)
|
||||
miss_texts = [texts[i] for i in ov_misses]
|
||||
|
||||
if miss_texts:
|
||||
# Translation memory: reuse this user's previous translations
|
||||
# (identical context/prompt) before hitting the provider.
|
||||
miss_translated = translate_with_tm(
|
||||
miss_texts, target_language, source_language,
|
||||
provider_name, getattr(self, "_tm_scope", None), _do_translate,
|
||||
)
|
||||
else:
|
||||
miss_translated = []
|
||||
|
||||
translated = []
|
||||
miss_pos = 0
|
||||
for i in range(len(texts)):
|
||||
if i in ov_hits:
|
||||
translated.append(ov_hits[i])
|
||||
else:
|
||||
translated.append(
|
||||
miss_translated[miss_pos]
|
||||
if miss_pos < len(miss_translated)
|
||||
else texts[i]
|
||||
)
|
||||
miss_pos += 1
|
||||
|
||||
recorder = getattr(self, "_segment_recorder", None)
|
||||
if recorder is not None:
|
||||
recorder.record_pairs(zip(texts, translated))
|
||||
|
||||
changed = sum(1 for orig, trans in zip(texts, translated) if orig != trans and trans.strip())
|
||||
self._translation_stats["changed"] += changed
|
||||
|
||||
Reference in New Issue
Block a user