Public API content
Use runtime content for public product titles, descriptions, and CMS text that does not exist at build time. Static interface copy continues through the compiler. Private customer messages and account-specific text are not supported: a publishable key is a public credential.
Runtime content is translated on demand. The first request for new text returns the source text immediately and translates it in the background, usually within one to two seconds. The translation is then stored permanently, so later requests and page refreshes are served from the cache.
How it works
- Cache. A translation is stored per project, target language, text, meaning note, and format. It is held in server memory and in the database. The browser SDK also keeps translations in memory and in
localStorage, so a refresh renders translated text without a network round trip. - Pending text. A request for text that has no translation yet returns the source text with state
pending. Identical concurrent requests trigger one translation. The browser SDK checks again with a short backoff and re-renders when the translation arrives. - Billing. Only first-time translations are charged, by target characters. Cached text and text you edited are free.
- Failures. If a translation fails, the entry is
unavailableand carries the source text. A failed translation is retried at most once a minute. - Fallback. Source text is always available, so a miss, a spending limit, or a provider failure never leaves a blank field.
Dashboard settings
Open API content in the dashboard. Each project has two settings:
- Translate new text automatically is off by default. When it is off, cached text is still served but new text stays in the source language.
- Monthly limit is the most this project can spend on runtime translation per month in USD (default $5). The organization spending cap also applies.
The page lists every cached translation. Search or filter by language and status, then:
- Edit overrides the translation. Edited text is marked "Edited" and is free.
- Retranslate deletes the cached entry, so the next request translates it again.
Browser integration
Create the client once per scope and dispose it on unmount. Browsers authenticate with a publishable key, which is subject to the project's allowed origins and rate limits.
import { createRuntimeClient } from "@linguanahq/core/runtime";
import { useRuntimeContent } from "@linguanahq/react";
const client = createRuntimeClient({
endpoint: "https://api.linguana.dev",
projectId: "your-project-id",
sourceLocale: "en",
locale: "de",
publishableKey: "your-publishable-key",
});
function Product({ product }) {
const { value } = useRuntimeContent(client, product, [
{ field: "title", meaning: "Product title" },
"description",
]);
return <article><h2>{value.title}</h2><p>{value.description}</p></article>;
}localize synchronously returns { value, fields }. It copies the object and changes only the selected top-level string properties. Unknown text renders as source text and is fetched in the background; listeners are notified when translations are ready. Empty or non-string fields are skipped with a diagnostic. IDs, prices, emails, and unselected fields remain untouched.
React and TanStack Start use useRuntimeContent(client, value, fields). Vue uses useRuntimeContent(client, () => value, fields), returning a computed ref. Solid uses the same accessor signature and returns a memo. Svelte uses runtimeContent(client, value, fields), returning a readable store; recreate the store when its input object changes. All of them re-render when translations arrive.
Client methods:
| Method | Purpose |
|---|---|
localize(value, fields) | Synchronous { value, fields } for an object |
text(source) | Synchronous best text for one string |
translate(sources) | Promise<string[]> that resolves when the texts are translated or unavailable |
subscribe(listener) / getSnapshot() | Subscribe to changes; returns an unsubscribe function |
setLocale(locale) | Switch the target language |
refresh() | Revalidate cached entries |
hydrate() | Serializable state for server rendering |
dispose() | Abort requests and clear subscriptions |
Options include storage (defaults to localStorage in browsers; pass false to disable persistence), hydrationState, timeZone, fetch, and onDiagnostic. Diagnostic codes are runtime-translate-failed, runtime-input-invalid, runtime-source-too-large, and runtime-field-skipped.
Plain text is the default. Braces and tags remain literal characters; render them as text, never with an HTML injection API. Use { source, format: "icu", meaning } only for actual ICU messages. The translated ICU message template is returned; interpolate values locally through an ICU formatter. No user values need to be sent to Linguana.
Server integration
Keep the project token on your server. Servers authenticate with Authorization: Bearer <secret project token>.
import { createRuntimeServerClient } from "@linguanahq/core/server";
const translator = createRuntimeServerClient({
endpoint: "https://api.linguana.dev",
projectId: "your-project-id",
sourceLocale: "en",
locale: "de",
token: process.env.LINGUANA_TOKEN!,
waitMs: 3000,
});
const [banner] = await translator.translate(["Free shipping"]);
const localized = await translator.localizeAsync(product, [
"title",
"description",
]);translate waits up to waitMs for new text and otherwise returns the source text. waitMs defaults to 3000 and cannot exceed 5000. localizeAsync returns a copy of the object with the selected fields translated.
Server rendering and hydration
Each SSR request must create its own client; do not share locale state between users. Translate on the server with the server client, then serialize client.hydrate() through your framework's safe serialization mechanism and pass it to the browser client as hydrationState. Ready translations render on the first paint without a flash of source text.
// Server: the server client waits for new text, so first renders are translated too
const translator = createRuntimeServerClient({ endpoint, projectId, sourceLocale, locale, token: process.env.LINGUANA_TOKEN! });
await translator.translate([product.title, product.description]);
const hydrationState = translator.hydrate();
// Browser
const client = createRuntimeClient({ endpoint, projectId, sourceLocale, locale, publishableKey, hydrationState });Hydration state must match the client's project and source language, otherwise the client throws RUNTIME_HYDRATION_SCOPE_MISMATCH.
Limits
- Up to 100 items and 20,000 source code points per request.
- A
meaningnote is at most 512 code points. waitMsis 0 to 5000 and is honored only for server callers.- Browser requests are rate limited and restricted to the project's allowed origins.
HTTP endpoint
All paths are under /api/v1. There is one endpoint:
POST /runtime/translate
Authenticate a browser with the x-linguana-key header (a publishable key). Authenticate a server with Authorization: Bearer <secret project token>.
{
"projectId": "your-project-id",
"sourceLocale": "en",
"locale": "de",
"items": [
{ "source": "Free shipping" },
{ "source": "{count, plural, one {# item} other {# items}}", "format": "icu", "meaning": "Cart summary" }
],
"waitMs": 3000
}Each item contains source, optional format (plain or icu), and optional meaning. The response is:
{
"projectId": "your-project-id",
"sourceLocale": "en",
"locale": "de",
"entries": [
{ "key": "…", "state": "ready", "text": "Kostenloser Versand" }
]
}| State | Meaning |
|---|---|
ready | text is the translation |
pending | A translation is in progress; text is the source text |
unavailable | The text cannot be translated now (code explains why); text is the source text |
The locale configuration endpoint used by framework providers, GET /runtime/projects/:project/environment/:environment, is separate and unchanged.
Translate product titles, CMS text, and other dynamic strings on demand, with permanent caching.
Last updated November 29, 2026
Did this page get you to a working result?