Tutorial

Pre‑Render Multilingual Gatsby Sites with SiteLocaleAI for SEO

Published November 7, 2026

Pre‑Render Multilingual Gatsby Sites with SiteLocaleAI for SEO

Introduction

Gatsby is a popular static‑site generator that builds fast, SEO‑friendly pages. When you want to reach a global audience, you need translated versions that search engines can crawl. SiteLocaleAI’s drop‑in JavaScript library makes it easy to generate multilingual pages at build time, while keeping the translation logic on your own LLM API keys.

In this tutorial we’ll:

  • Add SiteLocaleAI to a Gatsby project.
  • Configure the library to use your LLM (Claude, GPT‑4o‑mini, etc.).
  • Run the SEO pre‑render CLI so Google indexes fully translated HTML.
  • Deploy the static site to any host (Netlify, Vercel, etc.).

1. Install the library

npm install @sitelocaleai/gatsby

The package works with any framework, but the Gatsby integration adds a tiny wrapper that injects the translation script into every page.

2. Create a siteLocaleConfig.js

// siteLocaleConfig.js
module.exports = {
  // Your LLM provider – you supply the API key in an env var
  llm: {
    provider: "openai",          // or "anthropic", "google", …
    model: "gpt-4o-mini",
    apiKey: process.env.OPENAI_API_KEY,
  },

  // Languages you want to support
  locales: [
    { code: "en", name: "English" },
    { code: "es", name: "Español" },
    { code: "fr", name: "Français" },
  ],

  // Psychological price rounding per currency
  priceLocalization: {
    USD: (p) => Math.round(p),          // no cents
    EUR: (p) => Math.round(p * 0.95),   // 5 % discount rounding
    GBP: (p) => Math.round(p * 1.02),   // up‑sell rounding
  },

  // Optional: custom translation prompts
  prompt: "Translate the following HTML into {lang} while preserving HTML tags.",
};

Store the file at the project root. The configuration is read by both the client‑side script and the CLI.

3. Wire the library into Gatsby

gatsby-browser.js

import SiteLocale from "@sitelocaleai/gatsby";

export const onClientEntry = () => {
  SiteLocale.init({ config: require("./siteLocaleConfig") });
};

gatsby-ssr.js

import SiteLocale from "@sitelocaleai/gatsby";

export const onRenderBody = ({ setHeadComponents }) => {
  setHeadComponents([
    <script
      key="site-locale"
      src="https://cdn.sitelocaleai.com/locale.js"
      async
    />,
  ]);
};

The script loads the translation engine in the browser for dynamic language switches, while the CLI will generate static HTML for each locale.

4. Translate content at build time

SiteLocaleAI ships a CLI that crawls your built site, calls the LLM, and writes locale‑specific HTML files. Add a script to package.json:

{
  "scripts": {
    "build": "gatsby build",
    "prerender": "site-locale-cli --config siteLocaleConfig.js --output public"
  }
}

Run the pipeline:

npm run build && npm run prerender

The CLI does the following:

  1. Reads public/ (the static output of gatsby build).
  2. For each page, sends the HTML to the LLM with the prompt defined earlier.
  3. Writes a new folder for each locale, e.g. public/es/, public/fr/.
  4. Rewrites internal links so that /about/ becomes /es/about/ for Spanish, etc.

Because the pages are fully rendered HTML, Google can index them without JavaScript execution, giving you the same SEO benefit as a manually translated site.

5. Verify the output

Open a translated page locally:

npx serve public/es

You should see the Spanish version of your site, with prices rounded according to the priceLocalization rules. Inspect the source (View → Source) – the text is already translated, not generated on the client side.

6. Deploy

Push the public/ folder to your static‑host of choice. No server‑side code is required, and the LLM keys never leave your environment because translation happens during the pre‑render step.

7. Optional: WordPress integration

If you also run a WordPress blog, SiteLocaleAI offers a plugin that reads the same siteLocaleConfig.js and produces translated static snapshots for SEO. The plugin works without Node.js, making it a perfect complement to a Gatsby front‑end.

8. Next steps

  • Add hreflang tags to the <head> of each page – see the SEO guide for details.
  • Use the price‑localization callbacks to display region‑specific discounts.
  • Experiment with custom prompts for brand‑tone consistency.

Conclusion

With just a few npm commands and a small config file, you can turn any Gatsby site into a multilingual, SEO‑ready powerhouse. All translations run on your own LLM keys, keeping costs predictable and data private.

Ready to boost your global traffic? Try SiteLocaleAI today – the free Indie plan starts at $5/month, and the library works out‑of‑the‑box with Gatsby.