Ir al contenido
Sonenta
← All documentation

Quickstart · Astro

Use Sonenta in an Astro site

The official @sonenta/astro integration pulls your released translation bundles from the Sonenta CDN at build time and inlines them into your static HTML — zero client JS, pure SSG, no flash of untranslated content. This site runs on it.

1 · Create a project & get your keys

Sign in, create a project, and copy its UUID. You manage keys and translations in Sonenta — by talking to your agent over MCP, with the CLI, or in the dashboard.

2 · Install the package

Add the official Astro integration:

npm install @sonenta/astro

3 · Add the integration

Register it in astro.config.mjs with your project UUID, locales, and namespaces. Bundles are fetched once at build (locale × namespace). Extra options: version (default "main"), cdnBase, and fallbackLng.

// astro.config.mjs
import { defineConfig } from "astro/config";
import sonenta from "@sonenta/astro";

export default defineConfig({
  integrations: [
    sonenta({
      project: "<your-project-uuid>",
      locales: ["en", "fr"],
      defaultLocale: "en",   // source / fallback locale
      namespaces: ["common"],
    }),
  ],
});

4 · Use getT() in your pages

Import getT from the sonenta:i18n virtual module and bind it to a locale. Pass any locale you like — it works with Astro’s native i18n routing or your own. Address other namespaces with the "ns:key" syntax (e.g. t("docs:intro")); strings are inlined into the static HTML:

---
// src/pages/index.astro
import { getT } from "sonenta:i18n";
const t = getT(Astro.currentLocale ?? "en");
---
<h1>{t("home.title")}</h1>
<p>{t("home.greeting", { name: "Ada" })}</p>

5 · Publish, then rebuild

Manage source strings in Sonenta and publish a release (via your agent, the CLI, or the dashboard). The next astro build picks up the latest bundle:

# push your source strings to Sonenta + publish a release
npx @sonenta/cli push   # or let your agent do it over MCP
CLI →

We use it ourselves: this site runs on it

Sonenta.com — this page included — is built with @sonenta/astro: 13 locales across multiple namespaces, source strings pushed to Sonenta over MCP, released to the CDN, fetched at build, inlined as static HTML. The exact config above, at scale.

What’s next (0.2.0)

Accessibility surfaces (t.aria, t.alt), CLDR plurals, and responsive surface variants (desktop / mobile via <SurfaceText>) arrive additively in 0.2.0 — without breaking the API above.