Check 22.07 · International architecture

Avoid handling language only through cookies/JS

Find languages served by cookie, session or JavaScript on a single URL and replace them with server-rendered translated pages, in every environment.

Priority
Critical
Difficulty
Intermediate
Estimated time
2 h to 3 days
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

In short

A language handled only through cookies or JavaScript means a single URL that displays French or German depending on a cookie, a session, the browser's local storage or a translation script. Crawlers then see only one language. The task is to find these mechanisms and replace them with translated pages served under their own URLs, in the HTML returned by the server. The cookie can stay, but only to remember a choice, never to change the content of a URL.

Why it matters

Google documents this unambiguously: it recommends distinct URLs rather than cookies or browser settings to change the language of a page. Its rendering service keeps no state from one page to the next: cookies, local storage and session storage are cleared between page loads. Googlebot therefore always arrives "fresh": without a language cookie, it receives the default version, every time. The other languages do not exist for it.

JavaScript translation adds a second problem. Google renders JavaScript, but with a delay, and only what is displayed without interaction: a translation triggered by a click on a menu is never seen. Generative engine crawlers go further in the other direction: a study published by Vercel in December 2024 found that none of the major AI crawlers observed (including OpenAI, Anthropic and Perplexity) executed JavaScript. For them, only the language of the initial HTML counts.

Finally, a URL whose content depends on a cookie creates a caching problem: a CDN or caching plugin may serve one visitor the language chosen by the previous one.

What it improves

  • Indexing of secondary languages They become visible to Googlebot and Bingbot, which have no cookies.
  • Citations in AI answers The translated content is in the HTML read by crawlers that do not execute JavaScript. Effect not guaranteed.
  • hreflang It becomes possible to connect real URLs.
  • Cache reliability One URL, one language, one cacheable response.
  • Sharing A link opens the same language for everyone.

How to check

1. Does the content change depending on the cookie? Find the name of the language cookie in the browser's developer tools (Application or Storage tab), then:

curl -s https://example.com/tarifs | grep -o -i '<html[^>]*lang="[^"]*"'
curl -s -H "Cookie: lang=de" https://example.com/tarifs | grep -o -i '<html[^>]*lang="[^"]*"'

Expected result: the same language in both cases. A different language with the cookie indicates the problem.

2. Does the language depend on JavaScript? Compare the initial HTML with the displayed page:

curl -s https://example.com/de/preise/ | grep -c "Preise"

A result of 0 while the browser displays "Preise" means the translation is applied by a script. Also check by disabling JavaScript in the browser: the text must stay in the URL's language.

3. Does the switcher lead to URLs? In the source code, each switcher entry must be an <a href="/de/preise/"> link, not a button that sets a cookie or calls a function.

4. What Google sees: URL Inspection in Search Console, then "Test live URL" and "View tested page". The rendered HTML must be in the URL's language. See also compare initial HTML and rendered DOM (opens in a new tab).

How to implement

Before you start

The mechanisms to replace, and what replaces them:

Current mechanism Problem Replacement
Cookie or session that chooses a URL's language Crawlers have no cookies: only one language indexed Language in the URL (/de/), cookie limited to remembering the choice
JavaScript machine translation widget No translated page in the HTML Translated pages published under their own URLs
Single-page application that reads the language from local storage Client-side rendering, language invisible without execution Language prefix and server-side or static rendering
Switcher using onclick without href Crawlers do not follow the link <a href> links to the equivalent page

Prerequisite: each language has a distinct URL, see plan a separate URL for each language version (opens in a new tab).

Legitimate use of the cookie: remembering the chosen language in order to suggest it on the next visit to the root, as a suggestion. The content of a URL must never depend on it. If you set a preference cookie, it falls within the scope of your consent management: check its status against your privacy policy.

Apache

Versions Apache 2.4.

Look for rules that read a language cookie:

grep -rn -i "HTTP_COOKIE" /etc/apache2/ /var/www/ --include="*.conf" --include=".htaccess"

A rule like this one serves two languages under the same URL and must go:

# Remove: the same URL serves German if the cookie is present
RewriteCond %{HTTP_COOKIE} lang=de
RewriteRule ^(.*)$ /de/$1 [L]

Without the R flag, this rewrite is internal: the displayed URL stays /tarifs while the content is German. Remove it and let the switcher point to /de/preise/. Reload with sudo apachectl configtest && sudo systemctl reload apache2.

Nginx

Versions Nginx 1.24 and later.

Same search:

sudo grep -rn -E "cookie_|http_cookie" /etc/nginx/

A map $cookie_lang that changes the document root or the backend under the same URL must be removed:

# Remove
map $cookie_lang $site_root {
    default /var/www/example/fr;
    de      /var/www/example/de;
}

Instead, serve each language under its prefix:

location /de/ {
    root /var/www/example;
    try_files $uri $uri/ /de/index.html;
}

Then sudo nginx -t && sudo systemctl reload nginx.

Cloudflare

Versions Cloudflare dashboard, all plans, November 2026.

  • Cache: if a URL's HTML varies according to a language cookie, Cloudflare's cache may serve one visitor's language to another. With the language in the URL, the problem disappears without any extra rule.
  • Workers: a Worker that rewrites the content according to a cookie (for example with HTMLRewriter) recreates the flaw. Make it route to the language URL instead of translating in place.
  • After the fix, purge the cache: Caching > Configuration, "Purge Everything".

WordPress

Versions WordPress 6.8 to 7.1; WPML 5.x, Polylang 3.x.

  • Browser-side translation widgets: some plugins, often in their free version, translate the page on the fly with JavaScript without creating URLs. Check with the test in the "How to check" section: if the translated text does not appear in the HTML returned by curl, switch to a solution that publishes translated pages under their own URLs, such as WPML, Polylang, TranslatePress or Weglot.
  • WPML and Polylang set a language cookie, but their URLs carry the language: this cookie is harmless as long as the URL format uses directories, subdomains or domains. Polylang also uses it for its browser language detection on the homepage, which is covered in avoid forced redirects based on browser language (opens in a new tab).
  • Themes and page builders: check that the theme's strings (menus, buttons, footer) are translated on the server side, not injected by a script.

Purge the page cache after each change.

Shopify

Versions Shopify admin, all plans, November 2026.

The theme's language selector sends visitors to the URL of the chosen language, which is compliant. The risk comes from translation apps that translate the store with JavaScript in the browser, and from markets served on a shared domain: Shopify states that their content is not indexed. Give each market a subfolder or a domain and publish the languages with Translate & Adapt or an app that relies on Shopify's native languages.

Laravel

Versions Laravel 10 to 13.

The common pattern to replace reads the language from the session:

// To replace: the same URL changes language depending on the session
App::setLocale(session('locale', config('app.locale')));

Replace it with the language taken from the URL, using the SetLocale middleware and the route prefix described in plan a separate URL for each language version (opens in a new tab). The controller that used to change the language in the session becomes a simple link:

{{-- resources/views/partials/language-switcher.blade.php --}}
<nav aria-label="{{ __('Langue') }}">
    <a href="{{ route(Route::currentRouteName(), ['locale' => 'fr'] + request()->route()->parameters()) }}" hreflang="fr" lang="fr">Français</a>
    <a href="{{ route(Route::currentRouteName(), ['locale' => 'de'] + request()->route()->parameters()) }}" hreflang="de" lang="de">Deutsch</a>
</nav>

With the Laravel Localization package (mcamara, version 2.x for Laravel 11 to 13), do not use the localeSessionRedirect or localeCookieRedirect middleware on their own as the source of the language: the URL must remain decisive.

Next.js

Versions Next.js 15 and 16.

To avoid with both routers: a single unprefixed tree, translated on the client by a context provider that reads a cookie or local storage.

App Router

Put the pages under app/[lang]/ and load the translations in Server Components. The translated text is then in the initial HTML.

Pages Router

The NEXT_LOCALE cookie is only used to redirect from the root to the language prefix; the pages keep their URLs. This is acceptable if the redirect is not forced.

React, Vue or Angular without server-side rendering

A single-page application rendered only in the browser delivers nothing but an empty shell to crawlers. Two fixes, to be combined:

  1. Language in the URL: configure detection to read the path, and nothing else. With i18next:
import i18n from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import { initReactI18next } from 'react-i18next';

i18n
  .use(LanguageDetector)
  .use(initReactI18next)
  .init({
    supportedLngs: ['fr', 'de', 'en'],
    fallbackLng: 'fr',
    detection: {
      order: ['path'],
      lookupFromPathIndex: 0,
      caches: [],
    },
  });
  1. Translated HTML on the server side: static prerendering of every route in every language, or a move to a framework with server-side rendering (Next.js, Nuxt, Angular SSR). See prefer SSR/SSG for critical content if relevant (opens in a new tab).

Nuxt

Versions Nuxt 3.x and 4, @nuxtjs/i18n module 9 and 10.

With @nuxtjs/i18n, the no_prefix strategy serves every language under the same URLs and relies on a cookie: switch to prefix_except_default or prefix. Nuxt's server-side rendering then puts the translated text in the initial HTML.

Common mistakes

  • Believing Googlebot keeps the cookie set by the first page: it starts again with no state at every load.
  • Internal rewrite based on the cookie: the URL does not change, the content does.
  • A machine translation widget presented as a multilingual site.
  • A language switcher built as a JavaScript button without href.
  • Local storage as the source of truth for the language of a single-page application.
  • A shared cache on pages that vary by cookie: visitors served in the wrong language.
  • Testing while logged in with your own cookies: always test in a private window and with curl.

Frequently asked questions

Is a translation widget such as Google Translate enough for multilingual SEO?

No. A widget that translates the page in the browser creates no translated page: the HTML stays in the original language, with no URL of its own for each language. Search engines have nothing to index in the other languages, and crawlers that do not execute JavaScript only see the original. To be found in a language, publish reviewed, translated pages under their own URLs.

Do AI crawlers read translations done in JavaScript?

Most of the time, no. A study published by Vercel at the end of 2024 found that the major AI crawlers observed, including those of OpenAI, Anthropic and Perplexity, did not execute JavaScript. A translation applied by a script remains invisible to them, and they read the language of the initial HTML. Crawler behavior changes over time: serve the translated text in the server's HTML so you do not depend on any of them.

Updated on

Topic checklist (PDF)

And now?

In the “International architecture” topic

  1. Define target languages
  2. Define target countries
  3. Distinguish language from geotargeting
  4. Choose subdirectories, subdomains or country-code domains
  5. Plan a separate URL for each language version
  6. Translate slugs if relevant
  7. Avoid handling language only through cookies/JS
  8. Avoid forced IP-based redirects
  9. Avoid forced redirects based on browser language
  10. Provide a crawlable language switcher
  11. Link to the equivalent page rather than the homepage
  12. Plan for missing translations
  13. Check URL structure consistency
  14. Define the default version
  15. Avoid mixed-language pages with partial translations