Static Gatsby Site with Pre-rendered Translations for Google Indexing
Gatsby is a powerful static site generator, but adding multilingual support that search engines can index requires more than just client-side translation. Google needs static HTML for each language. In this guide, we'll show you how to use SiteLocaleAI to pre-render translations for your Gatsby site, ensuring every localized page is fully indexable.
Why Pre-rendering Matters for SEO
Search engines crawl static HTML. If your translations are applied dynamically via JavaScript, Google might miss them or index the default language only. Pre-rendering generates separate HTML files for each locale, complete with translated meta tags, content, and localized prices. This gives you:
- Indexed pages for every language
- Correct
hreflangtags - Faster load times (no runtime translation)
- Better user experience
Setting Up SiteLocaleAI in Your Gatsby Project
SiteLocaleAI is a self-hosted JS library that integrates with your existing LLM API keys. It works with any framework, but for Gatsby we'll use the CLI to pre-render translations at build time.
Step 1: Install the Package
npm install sitelocaleai
Step 2: Configure Your LLM API Key
Create a .env file in your project root:
SITELOCALE_API_KEY=your_claude_or_openai_key
SiteLocaleAI supports Claude, GPT-4o-mini, and other LLMs. You control the costs.
Step 3: Add Locales to Gatsby Config
In gatsby-config.js, define your supported locales:
module.exports = {
siteMetadata: {
locales: ['en', 'es', 'fr', 'de'],
defaultLocale: 'en',
},
plugins: [
// ... other plugins
],
};
Pre-rendering Translations with the CLI
SiteLocaleAI's CLI scans your built HTML files and generates translated versions for each locale. Add a script to package.json:
{
"scripts": {
"build": "gatsby build",
"localize": "sitelocaleai prerender --input public --locales es,fr,de"
}
}
Run npm run build && npm run localize. The CLI creates folders like public/es/, public/fr/, etc., each containing fully translated HTML files.
How It Works
The CLI:
1. Parses your static HTML.
2. Extracts text nodes and attributes.
3. Sends them to your LLM for translation.
4. Injects translations back into the HTML.
5. Localizes prices with psychological rounding (e.g., $49 → 49 €).
6. Adds hreflang tags for SEO.
Handling Dynamic Content and Components
For React components, you can use the SiteLocaleAI React wrapper to translate at build time. But for static sites, the CLI approach is simpler and ensures everything is pre-rendered.
If you have dynamic data (e.g., from GraphQL), make sure it's fetched at build time so it's included in the static HTML.
Localizing Prices
SiteLocaleAI automatically detects prices in your content and localizes them. For example, $49 becomes 49 € in Eurozone, with rounding to psychological price points (e.g., 49,99 € → 49 €). This boosts conversion and feels native.
SEO Benefits
With pre-rendered translations, you get:
- Indexable content: Each language has its own URL.
- Correct hreflang: The CLI adds
<link rel="alternate" hreflang="es" href="https://example.com/es/page" />. - Translated meta tags: Titles and descriptions are localized.
- Sitemap generation: Include all locales in your sitemap.
WordPress Plugin (Bonus)
If you also run WordPress, SiteLocaleAI offers a plugin with no Node.js required. It works similarly, pre-rendering translations for your WordPress site.
Conclusion
Pre-rendering translations is essential for international SEO on static sites. With SiteLocaleAI, you can leverage your own LLM keys to generate high-quality translations, localize prices, and ensure Google indexes every language version. The CLI makes it a breeze to integrate into your Gatsby build pipeline.
Ready to go global? Try SiteLocaleAI today and see your international traffic soar.
For detailed API references, visit our documentation.