International SEO on Astro with SiteLocaleAI – A Complete Guide
Published on SiteLocaleAI.com
🎯 Why Astro + SiteLocaleAI?
Astro’s static‑site generation gives you lightning‑fast pages, but out‑of‑the‑box it only serves one language. Pairing it with SiteLocaleAI—a drop‑in, framework‑agnostic JavaScript library—lets you:
- Translate every page on the fly using your own LLM API keys (Claude, GPT‑4o‑mini, etc.).
- Localize prices with psychological rounding per currency.
- Pre‑render translated pages for search engines via the SiteLocaleAI CLI, ensuring full indexing.
- Keep everything self‑hosted, so you stay compliant with data‑privacy policies.
In this guide we’ll walk through setting up an Astro project that serves 10 locales (EN, ES, FR, DE, IT, PT, NL, PL, JA, RU) with full SEO support.
📦 Prerequisites
| Requirement | Version |
|---|---|
| Node.js | >= 18 |
| Astro | 2.x |
| SiteLocaleAI library | npm package sitelocaleai |
| LLM API key | Claude, GPT‑4o‑mini, etc. |
| Git (optional) | any |
1️⃣ Install the SiteLocaleAI Library
# From your Astro project root
npm i sitelocaleai
This adds the library to your node_modules. Because SiteLocaleAI is framework‑agnostic, you can import it anywhere—React components, Vue files, or plain HTML.
2️⃣ Create a Locale Configuration
Create a file src/locale-config.js:
// src/locale-config.js
export const locales = [
{ code: "en", label: "English", currency: "USD" },
{ code: "es", label: "Español", currency: "EUR" },
{ code: "fr", label: "Français", currency: "EUR" },
{ code: "de", label: "Deutsch", currency: "EUR" },
{ code: "it", label: "Italiano", currency: "EUR" },
{ code: "pt", label: "Português", currency: "BRL" },
{ code: "nl", label: "Nederlands", currency: "EUR" },
{ code: "pl", label: "Polski", currency: "PLN" },
{ code: "ja", label: "日本語", currency: "JPY" },
{ code: "ru", label: "Русский", currency: "RUB" },
];
Feel free to add or remove locales later; the CLI will automatically pick them up.
3️⃣ Inject SiteLocaleAI into Your Layout
Assuming you have a global layout component src/layouts/Base.astro:
---
import { locales } from "../locale-config.js";
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><slot name="title" /></title>
<!-- SEO meta tags will be filled by the CLI (see step 5) -->
<script type="module">
import { SiteLocaleAI } from "sitelocaleai";
const aiKey = import.meta.env.SITELOCALEAI_API_KEY; // set in .env
const localeConfig = ${JSON.stringify(locales)};
const i18n = new SiteLocaleAI({
apiKey: aiKey,
locales: localeConfig,
defaultLocale: "en",
priceRounding: true,
});
i18n.init();
</script>
</head>
<body>
<slot />
</body>
</html>
The script loads the library, reads your API key from an environment variable, and initializes translation & price‑localization logic for every page.
4️⃣ Translate Content in Components
Inside any component you can now use the t helper:
---
import { useTranslation } from "sitelocaleai";
const { t, formatPrice } = useTranslation();
---
<h1>{t("Welcome to our store")}</h1>
<p>{t("Shop the best gadgets at unbeatable prices.")}</p>
<p>{t("Price:")} {formatPrice(49.99, "USD")}</p>
formatPrice automatically applies psychological rounding (e.g., $49.99 → $49.00) based on the locale’s currency.
5️⃣ Pre‑Render All Locales for SEO
SiteLocaleAI ships a CLI that crawls your static site, generates translated HTML files, and writes them to the dist folder. Run:
n ./node_modules/.bin/sitelocaleai-cli \
--src ./dist \
--locales ./src/locale-config.js \
--output ./dist/localized \
--api-key $SITELOCALEAI_API_KEY
The CLI:
- Fetches translations from your chosen LLM.
- Rewrites <title>, <meta description>, and Open Graph tags per locale.
- Generates language‑specific URLs (/en/, /es/, …) that search engines can index.
Tip: Add the CLI command to your
package.jsonscripts and run it as part of your CI pipeline.
{
"scripts": {
"build": "astro build && npm run locale:render",
"locale:render": "sitelocaleai-cli --src ./dist --locales ./src/locale-config.js --output ./dist/localized --api-key $SITELOCALEAI_API_KEY"
}
}
Now every locale gets its own fully‑rendered HTML page, guaranteeing that Google, Bing, and Yandex see the exact content you want indexed.
6️⃣ SEO Best Practices for Multi‑Locale Sites
| Practice | How SiteLocaleAI Helps |
|---|---|
| Hreflang tags | The CLI injects <link rel="alternate" hreflang="…" href="…" /> automatically. |
| Canonical URLs | Each localized page gets a self‑referencing canonical tag, preventing duplicate‑content penalties. |
| Localized Meta Descriptions | t can be used inside <meta name="description" content="…" /> in your layout. |
| Sitemap per Locale | After rendering, run astro build --sitemap and merge the generated sitemaps; the URLs already contain locale prefixes. |
7️⃣ Deploying the Site
Because the site is static, you can host it on any CDN (Vercel, Netlify, Cloudflare Pages). Ensure the environment variable SITELOCALEAI_API_KEY is set in the platform’s dashboard. No Node server is required at runtime—the translation work happens at build time.
8️⃣ Internal Resources
- Detailed API reference: https://sitelocaleai.com/docs/api
- CLI usage guide: https://sitelocaleai.com/docs/cli
9️⃣ Wrap‑Up
You now have a fully international Astro site that:
- Serves ten locales with SEO‑ready, pre‑rendered HTML.
- Localizes prices using psychological rounding.
- Remains self‑hosted, keeping your LLM keys private.
- Works with any front‑end framework or plain HTML.
Give it a spin and watch your global traffic climb!
🚀 Ready to go multilingual? Try SiteLocaleAI today and unlock the power of LLM‑driven translation for your Astro site.