Page localisation
Translate a page for one country and keep its layout.
On this page
Page localisation sends the page's text to Anthropic. Unlike the local threefold check, this is a hosted model call. The implementation is complete and verified locally. It was deployed on 18 November 2026. It is not verified against production, not counsel-reviewed, not marketplace-listed and not priced. Customer pricing remains PLACEHOLDER.
This page is the consumer contract for the stateless page-localisation call. The decision and its boundary are in direction.md. The four MCP tools are described in agent-tools.md. The short-text translate route in analysis.md is unchanged.
What it does
The call takes one page in one target variant (for example es-MX, de-DE or ja-JP) and returns the same page with only its text translated. It does three things:
- It translates text and nothing else.
- It keeps structure, links and their targets, images, non-text values, numbers, currency, dates, placeholders, protected phrases and default slugs exactly as sent.
- It returns a QA report. A node that fails a check keeps its source text, and the report lists it in
qa.retainedNodeswith a reason.
It is not a translation product in the wider sense. threefold does not store a customer's strings, keep a translation memory, sync a CMS, serve a proxy or overlay on a live site, or translate prices, currency or legal text. A caller that wants the result stored keeps it in its own CMS, repo or store. The one exception is a saved project: project_localise also reads that project's Country Voice (register, locked terms, forbidden phrases and approved edits), described in country-voice.md. The stateless calls below never read it.
What it sends to whom, and what is kept
Page text is sent to the model supplier, Anthropic today, for translation. See subprocessors and the privacy policy, section 2.C. Those two documents are drafts that counsel has not reviewed.
- No page text is stored, cached or logged by threefold. The page, its translation and the glossary sent with it are not kept.
- The usage ledger keeps only counts, tokens and cost.
- Idempotency is not applied to this route. An
Idempotency-Keyheader is ignored, and a retry is a new call that spends supplier cost again. The same applies to MCPcheckwithwhat: "page". - The local
threefold checkruns on the caller's machine and uploads nothing. The page call is a separate, server-side path.
Caching page text is off. John has not decided whether it may be cached.
Endpoint
POST /api/pages/localise, registry id localise_page. Scope analysis. The request body is JSON.
Authentication:
Authorization: Bearer tf_live_…with a key that has theanalysisscope.- Signed-in users use the web app session.
- OAuth tokens are accepted only through MCP (
/mcp), not on this REST route. - A keyless caller gets
401withsign_in_required. - A plan that does not include translate analyses gets
402withplan_limit.
Request
| Field | Type | Required | Meaning |
|---|---|---|---|
format | "html", "markdown", "document" or "nodes" | yes | Shape of content. |
content | string, object or array | yes | A string for html and markdown; a document object for document; an array of nodes for nodes. |
variant | string | yes | Target variant in BCP-47 language-REGION form, for example es-MX. |
market | string | no | Country code, for example mx. Default is derived from variant. |
niche | string | no | Niche context for the market glossary. |
glossary | array of {source, target}, or an object {source: target} | no | Caller terms. They win over the market glossary. |
protectedPhrases | string[] | no | Phrases that must appear unchanged. |
formality | "formal" or "informal" | no | Register. |
slugs | "keep" or "translate" | no | Default keep. Slugs are translated only on "translate", and then only returned as suggestions. |
sourceLanguage | string | no | Default is detected from the page, else en. |
Limits
Every limit is a hard 400 or 413 error, except the batch sizes (how a call is split into provider requests) and the per-call supplier cost guard. Source: modules/product/pages/limits.mjs.
| Limit | Value | Error page_code |
|---|---|---|
HTML or Markdown string (content) | 600,000 characters | content_too_large (413) |
| Nodes per call | 2,000 | too_many_nodes (413) |
| One plain, tagged or slug node | 20,000 characters | node_too_large (413) |
| Node id | 1 to 400 characters, unique within the call | duplicate_node_id (400) |
| One rich-text string inside nodes or document fields | 200,000 characters | content_too_large (413) |
| Document fields (every kind, containers included) | 2,000 | too_many_fields (413) |
| Document nesting depth | 16 | document_too_deep (413) |
| Field name | 1 to 200 characters | invalid_document (400) |
| Glossary entries | 300 (each term up to 160 characters) | invalid_glossary (400) |
| Protected phrases | 200 (each up to 160 characters) | invalid_input (400) |
| Segments sent to the model per call | 1,000 | too_many_segments (413) |
| Translatable characters sent to the model per call | 120,000 | too_much_text (413) |
| Batch | 40 items or 12,000 characters per provider request | not an error: it splits the call |
| Provider requests per call | 40, including splits after a bad provider answer | not an error: nodes past it are retained |
| Concurrent provider requests | 3 | not an error |
| Per-call supplier cost guard | USD 1 by default; THREEFOLD_PAGE_MAX_COST_USD overrides it | not an error: nodes past it are retained with reason cost_limit |
The per-call supplier cost guard limits known response costs plus estimated next-request cost; it cannot guarantee a hard invoice ceiling when requests time out or the SDK retries. It is not a customer price.
HTTP request bodies are capped at 1,000,000 bytes by the API handler, so the character limits are the second line of defence for CLI, MCP and library callers.
Nodes format
Each node is { "id": string, "text": string, "kind"?: string }. id is unique within the call and 1 to 400 characters. Node kinds:
text(default),heading,seo,alt,slug: plain text.slugis never overwritten in the content (see below).html,markdown: a rich string. It is parsed, and only text nodes and translatable attributes (alt,title,aria-label,placeholder, metacontent) are sent to the model. Markup, links, code and URLs are copied from the source by offset.tagged: rich text in the Portable Text codec. Marks are<N>…</N>(nestable) and inline objects are<N/>.Nis a number from 0 to 999999 and must stay. A literal<,>or&in the text is written as<,>or&, and the output uses the same escapes.- Any other kind matching
^[a-z][a-z0-9_-]{0,31}$, such asbutton,labelorcaption, is translated as plain text and echoed with its kind.
Slugs: with slugs: "keep" (the default), a slug node is not sent to the model and is returned unchanged. With slugs: "translate", it is translated and returned only as slugSuggestions. The page content is never overwritten with a slug.
Document format
format: "document" takes an explicit field tree. The top level is { "id"?: string, "fields": Field[] }. Each field has a name (1 to 200 characters, unique within its group, not required for list items) and a kind:
| Kind | Keys | Behaviour |
|---|---|---|
text | value: string, role? (text, heading, seo, alt, slug or another plain kind) | Translated as plain text. slug role is never overwritten. |
richText | format: "html", "markdown" or "tagged", value: string | Parsed as the matching rich format, structure kept. tagged uses the same codec as the tagged node kind. |
passThrough | value: any JSON | Copied byte-identical. Never sent to the model. |
group | fields: Field[] | A container of named fields. |
list | items: Field[] | A repeated container. Items are addressed by index. An item may be any kind, for example a group. |
Extra keys on any field are kept in the output and are never sent. An unknown kind is an invalid_document error.
Node ids for document fields are JSON-pointer paths from the root fields: /hero/title, /blocks/0/body. Inside a name, ~ is written ~0 and / is written ~1. Text inside a rich string has the id <parentId>#<startOffset>, where startOffset is the UTF-16 offset of the translated text or attribute value in the source string.
Example input (illustrative):
{
"format": "document",
"variant": "es-MX",
"protectedPhrases": ["Northstar"],
"content": {
"id": "page-1",
"fields": [
{ "name": "title", "kind": "text", "role": "heading", "value": "Plan your week" },
{ "name": "slug", "kind": "text", "role": "slug", "value": "plan-your-week" },
{
"name": "hero",
"kind": "group",
"fields": [
{ "name": "image", "kind": "passThrough", "value": { "asset": "img-1" } },
{ "name": "body", "kind": "richText", "format": "html", "value": "<p>Read the <a href=\"https://example.com/docs\">guide</a>.</p>" }
]
},
{
"name": "cards",
"kind": "list",
"items": [ { "kind": "group", "fields": [ { "name": "label", "kind": "text", "value": "Start free" } ] } ]
}
]
}
}
The output content has the same shape and key order. Only values of translated fields change. Names, kinds, ids, extra keys, passThrough values and the slug role are untouched.
Response
A 200 body is the bare engine result, with no wrapper. Its fields are:
| Field | Meaning |
|---|---|
format, variant, sourceLanguage | The format, the variant and the source language used. |
content | html or markdown: a string. nodes: an array of {id, text, kind} in the input order, with the kind echoed (default text). document: the document tree. |
qa.verdict | pass, warn, fail or unverified. Order of severity: fail, warn, unverified, pass. Items with status human_review never lower a pass. |
qa.findings[] | { nodeId | null, check, status, message }, plus kind, ruleId, matchedText, source, term, expected, found where they apply. status is fail, warn, unverified or human_review. |
qa.retainedNodes[] | { id, reason } for each node that kept its source text. |
qa.humanReview[] | { id, title, category, source, status: "human_review" }: the legal and launch checklist for the market. It is never a verdict. |
qa.counts | { nodes, translated, unchanged, retained, fail, warn, unverified, human_review }. |
qa.notLegalAdvice | Statement that the report is not legal advice. |
requests, costUsd | Provider requests made and estimated cost of responses with known usage. Failed or retried requests may incur additional unknown supplier charges. Not a customer price. |
models[] | Model ids as the provider served them. |
usage | { input, output, cacheRead, cacheWrite } token counts. |
provider.calls[] | Rawless per-attempt accounting: successful calls include { model, servedModel, items, tokens, costUsd, durationMs }; failed calls have status: "failed" and costUsd: null if usage is unknown. |
glossary | { source: "caller" | "market" | "caller+market" | "none", precedence: ["caller", "market"], rows: [{term, type, app_ids?, from}], market: {niche, market, variant, status} }. Rows are target-language terms, capped at 60. |
slugSuggestions? | [{ nodeId, source, suggestion, status: "suggested" }]. Present only with slugs: "translate". |
voice? | { locale, register, locked_terms, memory_matches, memory_replacements }. Present only when the project's Country Voice was applied (project_localise); never from the stateless call. |
qa.findings[].check is one of: placeholders, numbers, protected, brand, url, tags, structure, variant, glossary, untranslated, lang, hreflang, slug, provider, budget, legal, and voice (a forbidden phrase of the project's Country Voice; only from project_localise).
qa.retainedNodes[].reason is one of: placeholder_mismatch, number_changed, protected_phrase_altered, url_changed, tags_changed, structure_changed, not_returned, empty_translation, provider_failed, budget_exhausted, cost_limit.
A node that fails a check keeps its source text, and the reason is listed. Other nodes are still returned. Provider failures that are not aborts (malformed output, refusal, truncation, mid-run errors) retain the affected nodes with provider_failed and set the verdict to fail.
Masked items are placeholders ({name}, %s, ${x}), numbers, currency amounts, URLs, emails and protected phrases. Each travels to the model as an atomic <N/> tag that must be copied. A masked number that comes back altered or missing retains the node with number_changed. A number may also come back written out instead of its tag, if it has the same value and form (30 for the tag of 30); 4 000 or 4.000 for 4,000 is a changed number, because 4.000 is four in English and the check does not guess the reading.
Number rules (issues 266 and 154):
- A number counts wherever it stands. Japanese, Korean and Chinese write it directly against the next word (
手順2を,名前は30文字), Thai has no spaces between words (ภายใน30วัน), and Arabic and Hebrew put a one-letter prefix on it (ب30,بـ30,ב30); the check sees the number in each. In Latin, Cyrillic and Greek script a digit inside a word (v2,i18n) is still part of the word, not a number. - Native digits are the same number as ASCII digits: full-width (
2), Arabic-Indic (٣٠, with٫,٬and٪), Persian (۳۰), Devanagari (३०), Bengali (৩০) and Thai (๓๐). The model is asked for ASCII digits; an answer that still writes native digits with the right value passes and keeps them, and one with a wrong value or an added number isnumber_changed. Han numerals (二,十) are words, not numbers. - A multiplier written straight after a number is part of it:
$30written$30万(300,000 dollars) or4,000written4,000만(40 million) is a changed number. - For a Japanese, Korean or Chinese target (
ja,ko,zh, which coverszh-TWandzh-SG), the answer may add one number for each English number word in the source (four appsis4つのアプリ;onetoninety-nine,single,double,twice,triple, andper, becauseper dayis1日あたり) and for each English month name in a date (12 November 2026is2026年11月12日). An added number must stand against a Japanese, Korean or Chinese letter, or one space from it (4つ,1日,11월,2026 年 11 月), as a count does, and must not touch a currency sign,×,〜,+or another number ($30×4and13+1are rejected). Limit: when the answer has two equal numbers, the check cannot tell which one was added, so it judges the better placed of the two. Every other target keeps the exact rule: the same numbers, nothing added. Thai, Arabic, Hebrew, Hindi, Bengali, Russian, Greek, Czech, Hungarian and Vietnamese answers wrote number words as words on 24 Nov 2026, so they get no allowance. - Dates, for the same three targets: the day and year of a date (
12 November 2026,November 12, 2026,November 2026;Mayonly with a year or with the day before it, soMay 10 usersis not a date) are sent as plain digits, not markers, so the model can put the year first. The answer must then hold the date as month and day (11月12日,11월 12일) and the year (2026年,2026년). A swapped day, month or year (2026年12月11日,12年11月2026日) isnumber_changed, even though each number is there. - Dates, for every other target: the day and year stay behind markers, so their values come back exact in any order (
12 listopadu 2026,Νοέμβριο 12 2026,2026. november 12.). The answer must name the source's month in the target language (or in English), with its own day and year next to it (at most 12 characters and no digit between). A changed month, or a day swapped with another number of the node, isnumber_changed. The month names come from the ICU data in Node, with their case forms (ноября,ноябре). A language that writes the month as a number (Vietnamesetháng 11) gets the day and year as plain digits, like Japanese, and the month number is part of the date, not an added number. - A protected phrase is matched as text, so a particle or prefix written directly against it (
threefoldは,threefold의,وCodex) does not alter it. - Right-to-left answers: a bidi control (
U+200E,U+200F,U+061C, the embeddings and the isolatesU+2066toU+2069) inside a marker is dropped from the marker; elsewhere it stays in the text, and a URL ends before it. - Known gaps, logged in
docs/bugs.md: two numbers swapped inside one node pass, because numbers are compared as a set (BUG-098); a Han numeral before a kept number or a currency word after it passes (BUG-101).
Contiguous Markdown text and inline code within a paragraph, heading, list item, blockquote or table cell travel together as one segment with each inline code span held by a protected placeholder, while links and formatting (**bold**, link) still split at their boundaries; on merge, the original raw backtick bytes are spliced back verbatim without escaping (fixed in BUG-096, bugs-closed.md). Pure inline-code runs with no translatable letters are skipped.
Illustrative nodes response (labelled example, not a recorded run; costUsd and requests are placeholders for this example and are not measured values):
{
"format": "nodes",
"variant": "es-MX",
"sourceLanguage": "en",
"content": [
{ "id": "hero-title", "kind": "heading", "text": "Bienvenido a Northstar" },
{ "id": "cta", "kind": "button", "text": "Iniciar prueba gratuita" },
{ "id": "greeting", "kind": "text", "text": "Hola {name}, tu pedido está listo." }
],
"qa": { "verdict": "pass", "findings": [], "retainedNodes": [], "humanReview": [], "counts": { "nodes": 3, "translated": 3, "unchanged": 0, "retained": 0, "fail": 0, "warn": 0, "unverified": 0, "human_review": 0 }, "notLegalAdvice": "This report is not legal advice." },
"requests": 1,
"costUsd": 0,
"models": ["<served model id>"],
"usage": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 },
"provider": { "calls": [] },
"glossary": { "source": "none", "precedence": ["caller", "market"], "rows": [], "market": { "niche": null, "market": "mx", "variant": "es-MX", "status": "not_requested" } }
}
The example's translations and counts are illustrative. Do not read them as output from a live run.
Errors
Errors use the uniform error body { error, code, whose_error, retryable, hint }, plus page_code on page errors. The fields are:
code: one of the public codesinvalid_request,plan_limit,rate_limited,upstream_error,not_implemented,internal_error.page_code: a specific stable code, listed below.
Input errors (invalid_request):
page_code | HTTP |
|---|---|
invalid_input, invalid_variant, invalid_document, invalid_nodes, duplicate_node_id, invalid_glossary | 400 |
content_too_large, too_many_nodes, too_many_fields, node_too_large, document_too_deep, too_many_segments, too_much_text | 413 |
Provider aborts:
page_code | code | HTTP | Retryable |
|---|---|---|---|
not_configured | not_implemented | 501 | no |
auth | upstream_error | 502 | no |
rate_limited | rate_limited | 429 | yes |
timeout | upstream_error | 504 | yes |
api_error | upstream_error | 502 | yes |
budget | plan_limit | 503 | yes |
Plan and quota errors from modules/platform/limits.mjs pass through unchanged. A keyless caller gets 401 with sign_in_required. A plan without translate analyses gets 402 with plan_limit.
Cost and metering
- The call is metered as the
ai_briefcost family. Its price isPLACEHOLDER, not priced per call. - The workspace wallet or balance is not debited. The
X-Threefold-Cost-Micro-Usdheader is0. - The supplier cost (
costUsdin the response) counts against the workspace's monthly data budget and the deployment budget. It is recorded as a ledger row of kindtranslate. Translate rows count toward spend, not toward the plan's fresh analyses per month.
Sandbox
Sandbox keys, which have the tf_test_ prefix, may call POST /api/pages/localise and MCP check with what: "page".
- No model supplier is called and nothing is charged.
costUsdis0,requestsis0, andmodelsis["fixture"]. - The real parser and QA engine run with a deterministic fake translator. Each translated text becomes
[Fixture es-MX] <source text>, with the variant substituted. qa.verdictis real for the fixture output: structure, placeholders and URLs are genuinely checked.- The response shape is identical to a live call.
Use the sandbox to test integrations. It proves nothing about translation quality.
Caching
The route does not use the response cache, and Idempotency-Key is ignored. A repeated identical call is computed again, and its supplier cost is recorded again.
CORS
Browser calls from a Sanity Studio or any other web app need the caller's origin in THREEFOLD_STUDIO_ORIGINS.
THREEFOLD_STUDIO_ORIGINSis a comma-separated list of exact origins. Each origin must behttps://…orhttp://localhost…. There is no wildcard and no suffix matching.- Only origins in that list are allowed. Only
POST /api/pages/localiseanswers cross-origin requests among page routes. - A preflight
OPTIONSfrom an allowed origin returns204withmaxAge600. A preflight from any other origin returns403with no CORS headers. - An actual cross-origin request must carry
Authorization: Bearer. Credentials are not allowed: the request usescredentials: "omit", and the response never setsAccess-Control-Allow-Credentials. - The response sets
Vary: Originand exposesX-Threefold-Cost-Micro-UsdandRetry-After.
Example for a Studio on https://studio.example.com:
THREEFOLD_STUDIO_ORIGINS=https://studio.example.com,http://localhost:3333
REST check is refused
POST /api/agent/check with what: "page" is refused with 400 invalid_request, and the error points to POST /api/pages/localise. The generic check route caches responses, and page text must not be cached. Use the page route directly.
MCP: check with what: "page"
The page call is also available through the MCP tool check, with what: "page". This is the one exception to the rule that the agent writes the content (see agent-tools.md). It is still four MCP tools.
Arguments:
{
"what": "page",
"market": "mx",
"page": {
"format": "nodes",
"content": [ { "id": "cta", "kind": "button", "text": "Start free trial" } ],
"variant": "es-MX",
"niche": "health-fitness",
"protectedPhrases": ["Northstar"]
}
}
marketis the existing required argument ofcheck. It is passed to the engine asmarket.pagetakesformat,content,variant,niche,glossary,protectedPhrases,formality,slugsandsourceLanguage. It is strict: it does not acceptmarket.- The call needs an API key or OAuth token with the
analysisscope, notread. - The result has two parts.
content[0].textis a bounded digest of at most 4,000 characters: verdict, counts, retained nodes, cost and top findings. It never contains the page body.structuredContentis{ links, next, coverage, page }(the digest is only incontent[0].text), wherepageis the full engine result shown in Response. - The call is metered as the
ai_briefcost family. Its price isPLACEHOLDER. - A
what: "page"result cannot be saved with the workspacesaveaction. - The local stdio MCP server does not run the engine itself. It forwards the request to the HTTP route
POST /api/pages/localise, using the saved CLI login or API key (THREEFOLD_API_KEY,THREEFOLD_TOKEN, orthreefold login).
CLI
threefold localise-page <file> --variant es-MX calls the route above. With an API key it calls POST /api/pages/localise. With an OAuth login it calls MCP check with what: "page" and reads structuredContent.page. It does not run the engine in-process.
For OAuth, first run threefold login --scope "read analysis". An existing read-only login must be authorised again with the analysis scope. API keys also need that scope.
--format html|markdown|document|nodes. Default is inferred:.html/.htmishtml;.md,.markdownor.mdxismarkdown; a.jsonfile isnodesif it is an array (or{nodes: [...]}), anddocumentif it is an object withfields.--market mx,--niche health-fitness,--formality formal|informal,--slugs keep|translate,--source-language en.--glossary terms.csv|terms.json. CSV has a header rowsource,target(an optionalnotecolumn), and quoted fields are allowed. JSON is passed through as given.--protected brand.txt. One protected phrase per line. Blank lines and lines starting with#are ignored. A comma-split of--protectedis not done.--out translated.htmland--force. Without--out, the translated content goes to stdout (JSON fordocumentandnodes) and the QA summary goes to stderr.--outrefuses to overwrite an existing file unless--forceis given, and it never overwrites the input file.--report qa.jsonwrites{format, variant, sourceLanguage, qa, requests, costUsd, models, usage, glossary, slugSuggestions?, provider}, with nocontent.--jsonprints the full result JSON to stdout instead of the content and summary.
Exit codes: 0 when the verdict is pass or warn; 3 when it is fail or unverified (outputs are still written); 1 for an HTTP 4xx or 5xx, or a bad flag or file; 2 for a usage error.
Input files over about 950 KB are refused locally, because the HTTP body cap is 1,000,000 bytes.
Platform clients
Each integration is a client of this call. None is live, listed or priced.
- Shopify: an embedded app that previews the result for merchant review, then writes explicitly approved market-scoped translations through the Translations API.
- Sanity: a Studio plugin that creates a localised draft per document. Nothing is published automatically. It sends only text fields, and the Studio origin must be in
THREEFOLD_STUDIO_ORIGINS. - Vercel: a connectable integration that installs a threefold API key and environment variables. It has no native billing.
Cost
No supplier cost has been measured. The harness and its protocol are in research/page-localisation-costs.md. That note has no results yet. A measured figure would be a supplier cost, not a customer price.
Not yet verified
- The implementation was deployed on 18 November 2026 and has not been called in production.
- No live model call has been made under this route.
- Real-page quality is not reviewed by a person.
- Counsel has not reviewed the subprocessor and privacy entries.
- Shopify, Sanity and Vercel are not reviewed by their platforms and not listed.
Local verification is recorded in status.md. The live gates in that section (production deploy, live platform credentials and counsel review) remain open.