In short
This task continuously checks, on the live site, that each page is actually written in the language its URL announces. A script reads the pages of each version, detects the language of each block of text, of the title and of the meta description, then reports pages served in another language, mixed-language pages and wrong lang attributes. Scheduled every week, it turns a one-off check into a metric: the percentage of compliant pages per language.
Why it matters
Google says so explicitly: it determines the language of a page from its visible content, and uses neither the lang attribute nor the URL to do so. A /de/ page whose content has stayed in French is therefore, for the search engine, a French page. Google also points out that translating only the boilerplate (menus, footer) while leaving most of the content in a single language makes for a poor experience, with the same content appearing several times in the results.
These situations arise without anyone deciding them. Many systems display the default language when a translation is missing: Shopify says so in its documentation, and it is the default behavior of many frameworks and plugins. A block added by a plugin, a reviews widget, a custom field forgotten in the translation configuration, or a machine translation that failed without an error all produce the same effect.
The check at the source, described in detect untranslated strings (opens in a new tab), finds missing keys before publication. This one measures the actual result, page by page, as visitors, search engines and generative engine bots receive it.
What it improves
- Indexing in the right language Each version is recognized as such and can rank for the queries of its market.
- Duplicates avoided No
/de/page in French competing with the/fr/page. - Click-through rate Titles and descriptions in the language of the query.
- Conversion Fewer visitors faced with text they cannot read.
- Generative engines Indirect and unmeasured effect; a page that is consistent in its language is a clearer source for a question asked in that language.
How to check
Quick check on one page:
curl -s https://example.com/de/tees/gruener-tee/ | grep -o -i -E '<html[^>]*lang="[^"]*"|<title>[^<]*</title>'
Read the title and the lang attribute, then skim the text of the page. For a whole site, run the script from step 2 on a sample of each version.
Compliant result: the main language detected is the language of the URL on every page, the share of text in another language stays below the set threshold (documented exceptions aside), and the lang attribute matches.
How to implement
Step 1 — Define the rules and exceptions
| Check | Rule | Alert threshold |
|---|---|---|
| Main language of the content | The language of the URL (/de/ → German) |
Any difference |
| Share of text in another language | Low, exceptions aside | More than 15% of words (a starting point to adjust) |
| Title and meta description | In the language of the URL | Any difference on a text of at least three words |
lang attribute of <html> |
Code of the URL's language | Any difference |
Document the legitimate exceptions: brand and product names, quotations, customer reviews written in their original language, code snippets, invariable technical terms. A passage deliberately written in another language must carry its own lang attribute: see mark passages in another language (opens in a new tab).
Step 2 — Install the detection script
The script uses the Lingua library (lingua-language-detector, Python 3.12 or later), which works offline and stays accurate on short texts if you restrict detection to the site's languages. Install it in a virtual environment:
python3 -m venv .venv
. .venv/bin/activate
pip install lingua-language-detector
Save the script as langue_reelle.py:
#!/usr/bin/env python3
"""Detects the actual language of published pages and passages in another language."""
import argparse
import csv
import sys
import time
import urllib.request
import xml.etree.ElementTree as ET
from collections import Counter
from html.parser import HTMLParser
from lingua import Language, LanguageDetectorBuilder
LANGUAGES = {
"fr": Language.FRENCH,
"de": Language.GERMAN,
"en": Language.ENGLISH,
"es": Language.SPANISH,
"it": Language.ITALIAN,
"nl": Language.DUTCH,
}
BLOCK_TAGS = {"p", "li", "h1", "h2", "h3", "h4", "td", "th", "button", "label", "figcaption", "blockquote", "summary"}
IGNORED_TAGS = {"script", "style", "noscript", "template", "code", "pre", "svg"}
MIN_WORDS = 4
SITEMAP_NS = "{http://www.sitemaps.org/schemas/sitemap/0.9}"
class BlockParser(HTMLParser):
def __init__(self):
super().__init__()
self.lang = ""
self.title = ""
self.description = ""
self.blocks = []
self.current = []
self.ignored = 0
self.in_title = False
def handle_starttag(self, tag, attrs):
attributes = dict(attrs)
if tag == "html":
self.lang = (attributes.get("lang") or "").lower()
if tag == "title":
self.in_title = True
if tag == "meta" and (attributes.get("name") or "").lower() == "description":
self.description = attributes.get("content") or ""
if tag in IGNORED_TAGS:
self.ignored += 1
if tag in BLOCK_TAGS:
self.flush()
def handle_endtag(self, tag):
if tag == "title":
self.in_title = False
if tag in IGNORED_TAGS and self.ignored:
self.ignored -= 1
if tag in BLOCK_TAGS:
self.flush()
def handle_data(self, data):
if self.in_title:
self.title += data
elif not self.ignored:
self.current.append(data)
def flush(self):
text = " ".join(" ".join(self.current).split())
self.current = []
if len(text.split()) >= MIN_WORDS:
self.blocks.append(text)
def fetch(url):
request = urllib.request.Request(url, headers={"User-Agent": "langue-reelle/1.0"})
with urllib.request.urlopen(request, timeout=30) as response:
return response.read().decode(response.headers.get_content_charset() or "utf-8", errors="replace")
def read_sitemap(url):
root = ET.fromstring(fetch(url).encode("utf-8"))
urls = []
for loc in root.iter(f"{SITEMAP_NS}loc"):
if root.tag == f"{SITEMAP_NS}sitemapindex":
urls += read_sitemap(loc.text.strip())
else:
urls.append(loc.text.strip())
return urls
def detect(detector, text):
if len(text.split()) < 3:
return "?"
language = detector.detect_language_of(text)
return language.iso_code_639_1.name.lower() if language else "?"
arguments = argparse.ArgumentParser()
arguments.add_argument("sitemap")
arguments.add_argument("--prefix", action="append", required=True, help="prefix=language, for example https://example.com/de/=de")
arguments.add_argument("--threshold", type=float, default=0.15)
arguments.add_argument("--delay", type=float, default=0.3)
options = arguments.parse_args()
mapping = sorted((item.rsplit("=", 1) for item in options.prefix), key=lambda pair: len(pair[0]), reverse=True)
codes = {code for _, code in mapping} | {"en"}
detector = LanguageDetectorBuilder.from_languages(*(LANGUAGES[code] for code in codes)).build()
writer = csv.writer(sys.stdout)
writer.writerow(["url", "expected", "detected", "foreign_share", "problems", "examples"])
checked = 0
for url in read_sitemap(options.sitemap):
expected = next((code for prefix, code in mapping if url.startswith(prefix)), None)
if expected is None:
continue
parser = BlockParser()
try:
parser.feed(fetch(url))
parser.close()
parser.flush()
except OSError as error:
writer.writerow([url, expected, "", "", f"error: {error}", ""])
continue
checked += 1
words = Counter()
foreign = []
for block in parser.blocks:
code = detect(detector, block)
words[code] += len(block.split())
if code not in (expected, "?"):
foreign.append(block)
total = sum(words.values())
main = words.most_common(1)[0][0] if total else "?"
share = (total - words[expected] - words["?"]) / total if total else 0.0
problems = []
if total and main not in (expected, "?"):
problems.append(f"main language: {main}")
elif share > options.threshold:
problems.append(f"{share:.0%} of the text in another language")
for label, text in (("title", parser.title), ("description", parser.description)):
code = detect(detector, text)
if code not in (expected, "?"):
problems.append(f"{label} in {code}")
if parser.lang and parser.lang.split("-")[0] != expected:
problems.append(f'lang="{parser.lang}"')
if problems:
writer.writerow([url, expected, main, f"{share:.0%}", "; ".join(problems), " | ".join(foreign[:3])[:300]])
time.sleep(options.delay)
print(f"{checked} page(s) analyzed", file=sys.stderr)
Run it, giving the prefix of each version:
python3 langue_reelle.py https://example.com/sitemap.xml \
--prefix https://example.com/fr/=fr \
--prefix https://example.com/de/=de \
--prefix https://example.com/de-at/=de \
--prefix https://example.com/en/=en > langue-reelle.csv
Add your site's languages to the LANGUAGES dictionary (the full list is in the Lingua documentation). English is always included, because it is the most frequent language of untranslated leftovers (plugins, widgets). The script reads the initial HTML: for a client-side rendered site, use a headless browser (Playwright) to retrieve the rendered DOM. Blocks of fewer than four words are ignored, which rules out most brand names but also one-word buttons: those fall under the check of the language files.
Good to know: automatic language detection gets it wrong on very short texts, lists of proper names and closely related languages (Spanish and Catalan, Danish and Norwegian). Restricting the detector to the site's languages greatly reduces these errors. Treat each line of the report as a suspect to verify.
Step 3 — Without code: Google Sheets and a crawler
For a small site or an initial assessment:
- Crawl one version (
https://example.com/de/) with Screaming Frog and export the titles, meta descriptions and H1s (Page Titles,Meta DescriptionandH1tabs). The free version covers 500 URLs. - Paste the texts into Google Sheets and add a column
=IFERROR(DETECTLANGUAGE(B2),"?"). - Filter the rows whose result is not
de.
For the main content, Screaming Frog's custom extraction feature (Configuration > Custom > Custom Extraction, paid version) retrieves, for example, the first paragraph with the XPath expression (//main//p)[1], which you then pass to DETECTLANGUAGE.
Step 4 — Schedule and track
Run the script every week, for example in GitHub Actions, and keep the CSV from each run:
name: Actual language of pages
on:
schedule:
- cron: '0 6 * * 1'
workflow_dispatch:
jobs:
langue:
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: '3.13'
- run: pip install lingua-language-detector
- run: >
python3 scripts/langue_reelle.py https://example.com/sitemap.xml
--prefix https://example.com/fr/=fr
--prefix https://example.com/de/=de
--prefix https://example.com/en/=en > langue-reelle.csv
- uses: actions/upload-artifact@v7
with:
name: langue-reelle
path: langue-reelle.csv
Track one metric per language in the site's dashboard:
| Week | Language | Pages analyzed | Compliant pages | Compliance rate | Main cause |
|---|---|---|---|---|---|
| 2026-W47 | de | 412 | 389 | 94.4% | Reviews widget in French |
| 2026-W47 | en | 398 | 396 | 99.5% | Empty meta descriptions replaced with French |
| 2026-W48 | de | 415 | 411 | 99.0% | Fixed: widget translated |
A sudden drop in the compliance rate after a deployment signals a template or plugin regression: see test all versions after each deployment (opens in a new tab).
Step 5 — Fix according to the cause
| Symptom in the report | Likely cause | Fix |
|---|---|---|
| Main language = source language across the whole page | Fallback to the default language: translation missing or not published | Translate, or apply the rule for missing translations (opens in a new tab) |
| Same foreign block on every page of a version | Untranslated template, widget or plugin | Translate the string at the source; see translate dynamic content and CMS plugins (opens in a new tab) |
| Title or description in the source language | SEO field not translated, or SEO plugin fallback | See translate titles and meta descriptions (opens in a new tab) |
| High foreign share on a few pages | Content added after translation, customer reviews, quotations | Update the translation, or mark up the passage with its own lang |
Wrong lang attribute, correct content |
Template that writes the default language | See set html lang on each page (opens in a new tab) |
Fix the cause rather than the page: a corrected template block disappears from every page at once.
Common mistakes
- Relying on the
langattribute or the URL: Google determines the language from the visible content. - Detecting the language of the whole page as a single block: a page that is 70% translated passes as compliant while the purchase box is in the source language.
- Letting the detector choose among 75 languages: short texts then produce improbable languages.
- Not listing the exceptions (brands, reviews, quotations): the report fills up with false positives and stops being read.
- Checking once before launch: every plugin update can reintroduce untranslated strings.
- Ignoring metadata: a title in the source language is displayed directly in the results of the target market.
Frequently asked questions
How does Google determine the language of a page?
Google determines the language of a page from its visible content. Its documentation states that it does not use language information found in the code, such as the lang attribute, nor the URL. A page placed in the German directory but whose text has remained in French is therefore treated as a French page. The lang attribute is still useful for accessibility, browsers and other tools.
How do you automatically detect the language of a site's pages?
Retrieve the URLs from the sitemap, extract the text of each page block by block, then pass each block to a language detector such as the Lingua Python library, restricted to the site's languages. Compare the majority language with the one announced by the URL, measure the share of text in another language and also check the title, the meta description and the lang attribute. Schedule this check every week.
Why is a translated page displayed in the original language?
Most CMSs, platforms and frameworks display the default language when a translation is missing, without any visible error. Shopify documents this for its online store, and many translation plugins and libraries do the same. The translated page exists at its URL, but its content is the source content. You then need to translate the missing content or apply an explicit rule for missing translations.
What percentage of text in another language is acceptable?
There is no official threshold. Brand names, quotations, customer reviews and technical terms justify a small share of text in another language. An alert threshold of around 15% of words is a reasonable starting point, to be adjusted after the first checks. Above that, look at the page: most often, an entire template or content block has not been translated.
Resources
- Google Search Central: managing multi-regional and multilingual sitesdevelopers.google.com
- Google Search Central: localized versions of your pagesdevelopers.google.com
- Lingua for Python: documentationpypi.org
- Google Sheets Help: DETECTLANGUAGEsupport.google.com
- W3C: declaring language in HTMLw3.org
- Shopify Help: translating your storehelp.shopify.com
Updated on
Topic checklist (PDF)