> ## Documentation Index
> Fetch the complete documentation index at: https://ladygraph.io.vn/llms.txt
> Use this file to discover all available pages before exploring further.

# translation

> Aligned translation, escalation, verification and term hints.

Translating a passage so that what is found in the translation can still be pointed at in the original.

## `translation.aligned`

Aligned translation: the map between a source span and its translation is exact because the cuts are ours.

#### `Aligned`

| Field | Type | Default |
| - | - | - |
| `segments` | `list[Segment]` | required |
| `translations` | `list[str]` | required |
| `first_try_ok` | `bool` | required |
| `refilled` | `int` | required |
| `numbers_ok` | `list[bool]` | factory |

#### `AlignedConfig`

The wording of the two prompts.

| Field | Type | Default |
| - | - | - |
| `source_language` | `str` | `'the source language'` |
| `target_language` | `str` | `'English'` |
| `domain` | `str` | `'text'` |
| `keep` | `str` | `'Keep numbers, percentages, acronyms and formulas exactly; keep proper names as written.'` |

| Method | What it does |
| - | - |
| `numbered(self, lines: str) -> str` | — |
| `single(self, text: str) -> str` | — |

#### `AlignedTranslator`

`ask(prompt) -> reply text`: any model, local or remote.

Construct with `AlignedTranslator(ask: Callable[[str], str], config: AlignedConfig \| None = None)`.

| Method | What it does |
| - | - |
| `translate(self, raw: str, hint: str = '') -> Aligned` | — |

#### `Segment`

| Field | Type | Default |
| - | - | - |
| `start` | `int` | required |
| `length` | `int` | required |
| `text` | `str` | required |

#### `numbers_match`

```python theme={null}
numbers_match(source: str, translation: str) -> bool
```

The same numbers, as a multiset: a dropped or changed digit is the error that matters most in a rule.

#### `parse_numbered`

```python theme={null}
parse_numbered(reply: str, n: int) -> dict[int, str]
```

\{number: text} for the lines of `reply` that read `[k] text` with 1 \<= k \<= n.

#### `segments`

```python theme={null}
segments(raw: str) -> tuple[str, list[Segment]]
```

(the faithful passage, one Segment per non-empty line).

## `translation.checks`

Checks on a translation, as a function `check(source, translation) -> [problems]`; an empty list means it passed.

#### `basic`

```python theme={null}
basic(source: str, translation: str) -> list[str]
```

Empty answer, or numbers that differ from the source's.

#### `make_check`

```python theme={null}
make_check(glossary=None, extra: Sequence[Callable[[str, str], list[str]]] = ()) -> Callable[[str, str], list[str]]
```

`basic`, plus the term-list gate of `ladygraph.llm.translate` when a Glossary is given, plus any checks of your own.

## `translation.escalation`

Escalation: a cheap step first; stronger steps only for what the check rejects.

#### `Attempt`

| Field | Type | Default |
| - | - | - |
| `step` | `str` | required |
| `text` | `str` | required |
| `problems` | `list[str]` | required |

#### `Outcome`

| Field | Type | Default |
| - | - | - |
| `text` | `str` | required |
| `problems` | `list[str]` | required |
| `route` | `Literal['first', 'escalated', 'first_kept']` | required |
| `attempts` | `list[Attempt]` | factory |

| Method | What it does |
| - | - |
| `(property)` | — |

#### `Step`

| Field | Type | Default |
| - | - | - |
| `name` | `str` | required |
| `run` | `Callable[[str, str], str]` | required |
| `before` | `Callable[[str, list[str]], str] \| None` | `None` |

#### `escalate`

```python theme={null}
escalate(source: str, steps: list[Step], check: Callable[[str, str], list[str]], hint: str = '') -> Outcome
```

## `translation.hints`

Term hints: the glossary entries that occur in a text, as a note appended to a translation prompt.

#### `term_hint`

```python theme={null}
term_hint(text: str, glossary, *, statuses: tuple[str, ...] = ('approved', 'proposed'), header: str = 'Glossary (use these renderings)') -> str
```

"\n\nGlossary (...): term = rendering; ..." for the terms of `glossary` found in `text`, longest first, or "" when none is.

## `translation.verify`

Verification: a second model reads (source, translation) pairs and reports what is wrong, in a fixed vocabulary of error types.

#### `LlmVerifier`

Construct with `LlmVerifier(llm: LlmClient, *, source_language: str = 'the source language', target_language: str = 'English', domain: str = 'text', batch: int = 8)`.

| Method | What it does |
| - | - |
| `verify(self, pairs: Sequence[tuple[str, str, str]]) -> list[Verdict]` | — |

#### `Verdict`

| Field | Type | Default |
| - | - | - |
| `id` | `str` | required |
| `verdict` | `Literal['ok', 'minor', 'major', 'unchecked']` | required |
| `errors` | `list[VerdictError]` | `[]` |
| `note` | `str` | `''` |

#### `VerdictError`

| Field | Type | Default |
| - | - | - |
| `type` | `Literal['untranslated', 'name_mistranslated', 'wrong_term', 'number_dropped_or_changed', 'meaning_changed', 'added_text', 'missing_text']` | required |
| `source` | `str` | `''` |
| `translation` | `str` | `''` |
| `correct` | `str` | `''` |

#### `Verifier`

Construct with `Verifier(*args, **kwargs)`.

| Method | What it does |
| - | - |
| `verify(self, pairs: Sequence[tuple[str, str, str]]) -> list[Verdict]` | `pairs` are (id, source, translation). |

#### `verifier_check`

```python theme={null}
verifier_check(verifier: Verifier, fail_on: tuple[str, ...] = ('major',))
```

An escalation check (`check(source, translation) -> problems`) backed by a verifier: a verdict in `fail_on` becomes the problems.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.