Skip to content

Commit f7fc3ff

Browse files
authored
Add segment sources information (#143)
* Add translation source for document records * Make numbers substitution automated, not option * Generate client * Remove dead options from uploading dialog * Add UI to show segment sources
1 parent 9f5430b commit f7fc3ff

File tree

18 files changed

+274
-202
lines changed

18 files changed

+274
-202
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Add segment translation source
2+
3+
Revision ID: 3fbb82ea683d
4+
Revises: 32d5a77e6615
5+
Create Date: 2025-12-06 13:49:58.517637
6+
7+
"""
8+
9+
from typing import Sequence, Union
10+
11+
from alembic import op
12+
import sqlalchemy as sa
13+
14+
15+
# pylint: disable=E1101
16+
17+
# revision identifiers, used by Alembic.
18+
revision: str = "3fbb82ea683d"
19+
down_revision: Union[str, None] = "32d5a77e6615"
20+
branch_labels: Union[str, Sequence[str], None] = None
21+
depends_on: Union[str, Sequence[str], None] = None
22+
23+
segmentsource = sa.Enum(
24+
"glossary",
25+
"machine_translation",
26+
"translation_memory",
27+
"full_match",
28+
name="recordsource",
29+
)
30+
31+
32+
def upgrade() -> None:
33+
segmentsource.create(op.get_bind(), checkfirst=True)
34+
op.add_column(
35+
"document_record",
36+
sa.Column(
37+
"target_source",
38+
segmentsource,
39+
nullable=True,
40+
),
41+
)
42+
43+
44+
def downgrade() -> None:
45+
op.drop_column("document_record", "target_source")
46+
segmentsource.drop(op.get_bind(), checkfirst=True)

backend/app/documents/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ class Document(Base):
9797
)
9898

9999

100+
class RecordSource(Enum):
101+
glossary = "glossary"
102+
machine_translation = "mt"
103+
translation_memory = "tm"
104+
full_match = "fm" # for digits
105+
106+
100107
class DocumentRecord(Base):
101108
__tablename__ = "document_record"
102109

@@ -105,6 +112,7 @@ class DocumentRecord(Base):
105112
source: Mapped[str] = mapped_column()
106113
target: Mapped[str] = mapped_column()
107114
approved: Mapped[bool] = mapped_column(default=False)
115+
target_source: Mapped[RecordSource] = mapped_column(nullable=True)
108116

109117
document: Mapped["Document"] = relationship(back_populates="records")
110118
comments: Mapped[list["Comment"]] = relationship(

backend/app/documents/schema.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
from pydantic import BaseModel, Field
44

5-
from app.documents.models import TmMode
5+
from app.documents.models import RecordSource, TmMode
66
from app.glossary.schema import GlossaryResponse
77
from app.models import DocumentStatus, Identified, MachineTranslationSettings
8-
from app.translation_memory.schema import TranslationMemory, TranslationMemoryUsage
8+
from app.translation_memory.schema import TranslationMemory
99

1010

1111
class DocumentRecordFilter(BaseModel):
@@ -31,6 +31,7 @@ class DocumentRecord(Identified):
3131
approved: bool
3232
repetitions_count: int
3333
has_comments: bool
34+
translation_src: RecordSource | None
3435

3536

3637
class DocumentRecordListResponse(BaseModel):
@@ -52,9 +53,7 @@ class DocumentRecordUpdate(BaseModel):
5253

5354

5455
class DocumentProcessingSettings(BaseModel):
55-
substitute_numbers: bool
5656
machine_translation_settings: Optional[MachineTranslationSettings]
57-
memory_usage: TranslationMemoryUsage
5857
similarity_threshold: float = Field(default=1.0, ge=0.0, le=1.0)
5958

6059

backend/app/routers/document.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ def get_doc_records(
118118
query = GenericDocsQuery(db)
119119
total_records = query.get_document_records_count_filtered(doc, filters)
120120
records = query.get_document_records_paged(doc, page, filters=filters)
121-
122121
record_list = [
123122
doc_schema.DocumentRecord(
124123
id=record.id,
@@ -127,6 +126,9 @@ def get_doc_records(
127126
approved=record.approved,
128127
repetitions_count=repetitions_count,
129128
has_comments=has_comments,
129+
translation_src=record.target_source.value
130+
if record.target_source
131+
else None,
130132
)
131133
for record, repetitions_count, has_comments in records
132134
]

backend/app/translation_memory/schema.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from enum import Enum
2-
31
from pydantic import BaseModel, Field
42

53
from app.base.schema import Identified
@@ -11,11 +9,6 @@ class MemorySubstitution(BaseModel):
119
similarity: float
1210

1311

14-
class TranslationMemoryUsage(Enum):
15-
NEWEST = "newest"
16-
OLDEST = "oldest"
17-
18-
1912
class TranslationMemory(Identified):
2013
name: str
2114
created_by: int

backend/tests/fixtures/small.xliff

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<source xml:space="preserve">123456789</source>
2424
<target state="needs-translation" xml:space="preserve"></target>
2525
</trans-unit>
26+
<trans-unit id="675610" approved="no" sc:locked="false" sc:last-modified-date="2023-10-19T18:29:23.968Z" sc:last-modified-user="Person 5">
27+
<source xml:space="preserve">Something else</source>
28+
<target state="needs-translation" xml:space="preserve"></target>
29+
</trans-unit>
2630
</body>
2731
</file>
2832
</xliff>

backend/tests/routers/test_routes_doc_records.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
Document,
1111
DocumentRecord,
1212
DocumentType,
13+
RecordSource,
1314
)
1415
from app.translation_memory.models import TranslationMemory, TranslationMemoryRecord
1516

@@ -19,7 +20,11 @@
1920
def test_can_get_doc_records(user_logged_client: TestClient, session: Session):
2021
with session as s:
2122
records = [
22-
DocumentRecord(source="Regional Effects", target="Translation"),
23+
DocumentRecord(
24+
source="Regional Effects",
25+
target="Translation",
26+
target_source=RecordSource.translation_memory,
27+
),
2328
DocumentRecord(source="User Interface", target="UI", approved=True),
2429
]
2530
s.add(
@@ -46,6 +51,7 @@ def test_can_get_doc_records(user_logged_client: TestClient, session: Session):
4651
"approved": False,
4752
"repetitions_count": 1,
4853
"has_comments": False,
54+
"translation_src": "tm",
4955
},
5056
{
5157
"id": 2,
@@ -54,6 +60,7 @@ def test_can_get_doc_records(user_logged_client: TestClient, session: Session):
5460
"approved": True,
5561
"repetitions_count": 1,
5662
"has_comments": False,
63+
"translation_src": None,
5764
},
5865
]
5966

@@ -94,6 +101,7 @@ def test_doc_records_returns_second_page(
94101
"approved": False,
95102
"repetitions_count": 1,
96103
"has_comments": False,
104+
"translation_src": None,
97105
}
98106

99107

backend/tests/routers/test_routes_documents.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from app.models import DocumentStatus
2626
from app.schema import DocumentTask
2727
from app.translation_memory.models import TranslationMemory
28-
from app.translation_memory.schema import TranslationMemoryUsage
2928

3029
# pylint: disable=C0116
3130

@@ -296,9 +295,7 @@ def test_process_sets_document_in_pending_stage_and_creates_task_xliff(
296295
response = user_logged_client.post(
297296
"/document/1/process",
298297
json={
299-
"substitute_numbers": False,
300298
"machine_translation_settings": None,
301-
"memory_usage": TranslationMemoryUsage.NEWEST.value,
302299
},
303300
)
304301

@@ -318,9 +315,7 @@ def test_process_sets_document_in_pending_stage_and_creates_task_txt(
318315
response = user_logged_client.post(
319316
"/document/1/process",
320317
json={
321-
"substitute_numbers": False,
322318
"machine_translation_settings": None,
323-
"memory_usage": TranslationMemoryUsage.NEWEST.value,
324319
},
325320
)
326321

@@ -340,9 +335,7 @@ def test_process_creates_task_for_xliff(
340335
response = user_logged_client.post(
341336
"/document/1/process",
342337
json={
343-
"substitute_numbers": False,
344338
"machine_translation_settings": None,
345-
"memory_usage": TranslationMemoryUsage.NEWEST.value,
346339
},
347340
)
348341

@@ -356,9 +349,7 @@ def test_process_creates_task_for_xliff(
356349
"type": "xliff",
357350
"document_id": 1,
358351
"settings": {
359-
"substitute_numbers": False,
360352
"machine_translation_settings": None,
361-
"memory_usage": "newest",
362353
"similarity_threshold": 1.0,
363354
},
364355
}
@@ -371,9 +362,7 @@ def test_process_creates_task_for_txt(user_logged_client: TestClient, session: S
371362
response = user_logged_client.post(
372363
"/document/1/process",
373364
json={
374-
"substitute_numbers": False,
375365
"machine_translation_settings": None,
376-
"memory_usage": TranslationMemoryUsage.NEWEST.value,
377366
},
378367
)
379368

@@ -387,9 +376,7 @@ def test_process_creates_task_for_txt(user_logged_client: TestClient, session: S
387376
"type": "txt",
388377
"document_id": 1,
389378
"settings": {
390-
"substitute_numbers": False,
391379
"machine_translation_settings": None,
392-
"memory_usage": "newest",
393380
"similarity_threshold": 1.0,
394381
},
395382
}
@@ -401,9 +388,7 @@ def test_returns_404_when_processing_nonexistent_doc(
401388
response = user_logged_client.post(
402389
"/document/1/process",
403390
json={
404-
"substitute_numbers": False,
405391
"machine_translation_settings": None,
406-
"memory_usage": TranslationMemoryUsage.NEWEST.value,
407392
},
408393
)
409394
assert response.status_code == 404

0 commit comments

Comments
 (0)