[ Astro ]

Add i18n to an Astro site automatically

Polyglot wraps template and frontmatter strings, generates a typed translation util, and render-verifies the result — prerendered HTML with no leaked syntax.

1 Min. LesezeitAlle Frameworks

Astro has no single dominant i18n library, so Polyglot generates a small typed utility (src/i18n/utils) and wraps your templates against it — the whole system arrives together and is verified together.

The transformation

Before — src/pages/index.astro
---
const title = "internal";
---

<html>
  <body>
    <h1>Welcome back</h1>
    <p>Your projects are ready</p>
  </body>
</html>
After — src/pages/index.astro
---
import { getLangFromUrl, useTranslations } from "../i18n/utils";
const lang = getLangFromUrl(Astro.url);
const t = useTranslations(lang);
const title = "internal";
---

<html>
  <body>
    <h1>{t('src.pages.index.welcome_back')}</h1>
    <p>{t('src.pages.index.your_projects_are_ready')}</p>
  </body>
</html>

Both template markup and frontmatter strings are handled; the generated useTranslations util resolves keys against the JSON catalogs translate maintains.

Setup and catalogs

Written — messages/en.json
{
  "src.pages.index.welcome_back": "Welcome back",
  "src.pages.index.your_projects_are_ready": "Your projects are ready"
}
Translated — messages/de.json
{
  "src": {
    "pages": {
      "index": {
        "welcome_back": "Willkommen zurück",
        "your_projects_are_ready": "Ihre Projekte sind bereit"
      }
    }
  }
}
Translated — messages/fr.json
{
  "src": {
    "pages": {
      "index": {
        "welcome_back": "Bon retour",
        "your_projects_are_ready": "Vos projets sont prêts"
      }
    }
  }
}

Because Astro prerenders, this combination is covered by Polyglot's end-to-end matrix as a render-checked framework: real repos are cloned, wrapped, built, and their emitted HTML checked for content with zero leaked i18n syntax.

✓ 2 strings auto-wrapped · 0 flagged for manual review · 0 unsafe transforms → polyglot-i18n-report.md
✓ wiring checks passed (1 injected import(s), 2 catalog value(s), 1 catalog file(s))

Try it

$ curl -fsSL https://getpolyglot.ai/install.sh | sh
$ polyglot init --framework astro
$ polyglot scan
$ polyglot wrap
$ polyglot translate --languages de   # 50 strings free, no signup

Im Terminal starten

Schluss mit der Suche nach unübersetzten Strings.

Installieren Sie die CLI, führen Sie einen Scan durch und sehen Sie genau, was Ihnen fehlt. Kostenlos, kein Konto erforderlich.

$curl -fsSL https://getpolyglot.ai/install.sh | sh
Add i18n to an Astro site automatically | Polyglot