Introduction
If you’re building a static site with Astro and need to serve 10 locales while keeping search‑engine rankings intact, you’ve probably explored a few options: server‑side translation middleware, pre‑rendered static files per language, or a third‑party SaaS translation layer. Each approach has trade‑offs in performance, cost, and control.
SiteLocaleAI flips the script. By using a drop‑in JavaScript library that runs entirely in the browser, combined with a CLI for SEO pre‑rendering, you get the speed of a static site, the flexibility of client‑side translation, and the SEO guarantees of server‑side rendering—all while keeping your LLM API keys private.
Below we compare the typical approaches and then walk through a concrete implementation for an Astro site.
Common Approaches
| Approach | How it works | SEO impact | Cost | Maintenance |
|---|---|---|---|---|
| Server‑side middleware (e.g., Next.js i18n) | Translate on each request using an LLM API. | Good for crawlers if you render HTML on the server, but adds latency. | High (per‑request LLM calls). | Requires a node server, scaling concerns. |
| Static pre‑render per locale | Generate separate HTML files for each language at build time. | Excellent SEO – static HTML is indexed. | Moderate (build time grows with locales). | Build scripts become complex; price localization must be baked in. |
| Third‑party SaaS translation layer | Embed a widget that calls a remote service. | Poor SEO – crawlers see only the original language. | Subscription fees. | Limited control, data privacy concerns. |
| SiteLocaleAI (self‑hosted) | Drop‑in JS library loads translations from your own LLM API keys; CLI pre‑renders translated pages for crawlers. | Full SEO – static pages are generated for each locale. | Low (only LLM usage, no server cost). | Simple – just the library and a CLI command. |
Why SiteLocaleAI wins for Astro
- Framework‑agnostic – works with Astro’s component model without any build‑time hacks.
- Self‑hosted LLM keys – you stay in control of data and pricing (Claude, GPT‑4o‑mini, etc.).
- Psychological price rounding – automatically adjusts prices per currency (e.g., $9.99 → €8.99).
- CLI SEO pre‑renderer – generates static HTML for each locale, so Google indexes the translated content.
- Zero Node.js requirement for WordPress – if you ever need a hybrid site, the plugin works out‑of‑the‑box.
Step‑by‑Step Implementation
1. Install the library
npm i @sitelocaleai/core
The package works in any bundler (Vite, Webpack, Snowpack) or even as a plain
<script>tag.
2. Initialize SiteLocaleAI in your Astro layout
Create a src/components/LocaleProvider.astro:
---
import { initLocaleAI } from '@sitelocaleai/core';
// Your LLM provider configuration – keep the API key secret on the server.
const localeConfig = {
provider: 'openai', // or 'anthropic', 'cohere', etc.
apiKey: import.meta.env.SITELOCALEAI_API_KEY,
defaultLocale: 'en',
supportedLocales: ['en', 'es', 'fr', 'de', 'it', 'pt', 'ja', 'zh', 'ru', 'ar'],
// Optional price rounding rules
priceRules: {
usd: (p) => Math.round(p * 100) / 100,
eur: (p) => Math.round(p * 100) / 100 - 0.01,
// add more as needed
},
};
// Initialise once on the client side
if (typeof window !== 'undefined') {
initLocaleAI(localeConfig);
}
---
<slot />
Add the provider to your root layout (src/layouts/BaseLayout.astro):
---
import LocaleProvider from '../components/LocaleProvider.astro';
---
<LocaleProvider>
<slot />
</LocaleProvider>
3. Mark translatable content
Use the data-locale-key attribute or the helper function t() provided by the library.
<h1 data-locale-key="hero.title">Welcome to Our Store</h1>
<p data-locale-key="hero.subtitle">Best products at the best prices.</p>
<!-- Price example -->
<p>
<span data-locale-key="price.label">Price:</span>
<span data-price="49.99" data-currency="usd" class="price"></span>
</p>
The library will replace the text and format the price according to the visitor’s locale, applying psychological rounding rules defined earlier.
4. Generate SEO‑friendly static pages
SiteLocaleAI ships a CLI that crawls your site, fetches translations via your LLM API, and writes static HTML files per locale.
npx @sitelocaleai/cli pre-render \
--src ./dist \
--out ./dist-localized \
--locales en,es,fr,de,it,pt,ja,zh,ru,ar \
--api-key $SITELOCALEAI_API_KEY
--srcpoints to the built Astro output.--outis where the localized HTML lives.- The CLI respects your
priceRulesand injects the correct<link rel="alternate" hreflang="...">tags for search engines.
After the command finishes, you can serve the dist-localized folder with any static host (Netlify, Vercel, Cloudflare Pages). Each locale gets its own URL, e.g., /es/ for Spanish.
5. Verify SEO with the built‑in sitemap generator
SiteLocaleAI can append locale‑specific entries to your sitemap:
npx @sitelocaleai/cli generate-sitemap \
--base https://example.com \
--locales en,es,fr,de,it,pt,ja,zh,ru,ar \
--out ./dist-localized/sitemap.xml
Submit the sitemap to Google Search Console and watch the indexed pages appear in each language.
Comparison Recap
| Metric | Server‑Side Middleware | Static Pre‑Render | SiteLocaleAI |
|---|---|---|---|
| Performance | Request‑time latency | Fast but large build | Fast + minimal runtime overhead |
| SEO | Good if SSR is used | Excellent | Excellent (static HTML per locale) |
| Cost | High per request | Moderate build cost | Low (only LLM usage) |
| Control | Limited (vendor API) | High (but static) | High (self‑hosted keys, custom rounding) |
| Complexity | Requires server | Build scripts | Simple CLI + one‑line init |
For an Astro site that already outputs static HTML, SiteLocaleAI adds zero runtime server cost while giving you full SEO control and price‑localization that other solutions lack.
Try SiteLocaleAI Today
Ready to launch a multilingual Astro site with perfect SEO and localized pricing? Get started for free and see how a few lines of code can unlock 10 new markets in minutes.
Need more details? Check out the official documentation:
- https://sitelocaleai.com/docs/installation
- https://sitelocaleai.com/docs/cli