Skip to content
PlacementGraph™
Language detection

How is the language of a page detected?

Part of Contextual targeting

A person reading a magazine in a quiet, book-lined lounge.

The short answer

Page language is detected by running a statistical model over the article's main text and comparing its letter and word patterns with patterns learned for each language. It describes the page, not the reader, whose browser setting is a separate signal. Detection weakens on short text, closely related languages and mixed language passages, which is when a person should check.

Key takeaways

  • Language detection reads the article text and returns a best guess with some measure of confidence, not a fact.
  • The language of a page and the language setting of a reader's browser are separate signals, and OpenRTB carries them in separate fields.
  • Short text, closely related languages, foreign names and mixed language passages are the documented ways detection goes wrong.
  • An uncertain result should be recorded as uncertain and checked by a reader of the language, not forced into one label.
  • A bilingual page is best labeled with its main language plus the share and place of the second language.

How is the language of a page detected?

Detection starts with the right text. Menus, footers, cookie banners and ads are stripped away so the model sees the article itself, because a French article inside an English site template would otherwise read as partly English. The model then compares the text's patterns, such as which short letter sequences and words appear and how often, with the patterns it learned for each language, and returns the most likely language with a score.

The W3C describes the method plainly in its working draft Strings on the Web: Language and Direction Metadata (opens in a new tab) (First Public Working Draft, July 16, 2026): detectors "are usually statistically based heuristics, such as using n-gram frequency in a language, possibly coupled with other data." The same section says the approach "is NOT recommended" as a substitute for explicit language metadata in data formats, which is a reminder that detection is a fallback when no one has labeled the text.

Definition

Content language detection
Identifying the language of a text from the text itself, using a model trained on examples of each language. Also called language identification.
From a web page to a language label
From a web page to a language labelEach step can lower confidence. An uncertain result is kept as uncertain. 1. Fetch the page: Read the article, not the homepage. 2. Extract main text: Drop menus, ads and comments. 3. Split into segments: Paragraphs or sentences. 4. Score each segment: Most likely language and confidence. 5. Label the page: Main language, plus any second one01Fetch thepageRead the article,not the homepage02Extract maintextDrop menus, adsand comments03Split intosegmentsParagraphs orsentences04Score eachsegmentMost likelylanguage andconfidence05Label thepageMain language,plus any secondone
From a web page to a language labelEach step can lower confidence. An uncertain result is kept as uncertain. 1. Fetch the page: Read the article, not the homepage. 2. Extract main text: Drop menus, ads and comments. 3. Split into segments: Paragraphs or sentences. 4. Score each segment: Most likely language and confidence. 5. Label the page: Main language, plus any second one01Fetch the pageRead the article, not thehomepage02Extract main textDrop menus, ads and comments03Split into segmentsParagraphs or sentences04Score each segmentMost likely language andconfidence05Label the pageMain language, plus any secondone
Each step can lower confidence. An uncertain result is kept as uncertain.

Why is page language different from a user's language setting?

The two describe different things. Page language describes what the article is written in. A browser's language setting describes what the reader asked for, and it can be wrong about the reader. The W3C's note on Accept-Language (opens in a new tab) says the header carries "information about the user's language preferences" and warns: "Many users never change the defaults for Accept-Language." It also notes that people borrow and share machines.

The ad tech standard keeps them apart as well. In the OpenRTB 2.6 specification (opens in a new tab), the Content object's language field is "Content language using ISO-639-1-alpha-2", while the Device object's language field is "Browser language using ISO-639-1-alpha-2". Both also have a langb version using IETF BCP 47 tags. A bilingual reader in San Antonio may run an English browser and read Spanish news; a contextual plan cares about the second fact.

Page language and reader language are separate signals
SignalWhat it describesWhere it comes fromWhat it cannot tell you
Detected page languageThe language of the article's main textA model run over the textWho is reading or what they prefer
Declared page languageWhat the publisher says the page is inThe lang attribute in the page codeWhether the text actually matches it
Browser languageWhat the reader's software requestsAccept-Language header or device settingsWhich language the reader reads best, or what is on the page

What causes language detection to fail?

The failure modes are well documented. The W3C draft lists them in its issues section. Heuristics are "more accurate the longer and more representative the text being scanned is", and "Short strings may not detect well." Detection "is limited to the languages for which one has a detector." And: "Inclusions, such as personal or brand names in another language or script, can throw off the detection."

Research adds two more. A 2025 ACL paper by Rob van der Goot, Identifying Open Challenges in Language Identification (opens in a new tab), found that "cross-domain setups are the most challenging": a model trained on one kind of text does worse on another, so a detector should be tested on the kind of pages it will classify. And a 2024 LREC-COLING paper on FastSpell (opens in a new tab) says that "commonly used language identifiers struggle to differentiate between similar or closely-related languages", its reason for adding a spell checker as a second opinion.

Documented causes of language detection errors, and what they look like on web pages
CauseSourceWhat it looks like on a site
Short textW3C string-meta draft, 5.4.3Photo galleries, recipe cards and event listings with a few lines of text
Names from another languageW3C string-meta draft, 5.4.3An English review full of Spanish dish and place names
Language not coveredW3C string-meta draft, 5.4.3A language the detector was never trained on, labeled as a near neighbor
Closely related languagesFastSpell, LREC-COLING 2024Spanish and Portuguese, or similar pairs, swapped on short passages
Different kind of textvan der Goot, ACL 2025Forum posts or slang heavy columns scored by a model trained on cleaner text
Mixed languagesBurchell and colleagues, EACL 2024Articles that switch between English and Spanish within a paragraph

When should an uncertain language result go to manual review?

No standard sets a confidence cutoff for review, so each team sets its own and writes it down. The useful rule is to send a result to a person when the cause of doubt is one the model is known to handle badly, or when a wrong label would change the plan. A Spanish language site wrongly labeled English drops out of a Spanish brief; an English site wrongly labeled Spanish fills a Spanish list with pages the client's ads do not match.

Send the page to a reader of the language when

  • The main text is short, such as a gallery, listing or caption led page.
  • Two languages score close to each other.
  • The detected language disagrees with the publisher's declared language.
  • The page mixes languages within paragraphs, not only in separate sections.
  • The detected language is one the brief targets and the site would be excluded or kept on this result alone.
  • Several sampled articles from the same site disagree with each other.

How should bilingual pages be labeled?

Start with how publishers are told to declare it. The W3C's guidance on declaring language in HTML (opens in a new tab) gives two rules: "Always use a language attribute on the html tag to declare the default language of the text in the page", and "When the page contains content in another language, add a language attribute to an element surrounding that content." One main language for the page, with marked passages in another, is the model a planner's label can follow.

Detection should then work at the level of passages. The EACL 2024 paper Code-Switched Language Identification is Harder Than You Think (opens in a new tab) reformulates the task "as a sentence-level multi-label tagging problem" and concludes that "no current approach is adequate" for text that switches languages. For planning, that argues for scoring paragraphs or sentences separately and keeping more than one label on the page, rather than one label for the whole article.

A labeling scheme for pages with more than one language
Page patternLabel to recordPlanning note
One language throughoutMain language onlyPlan it with that language's list
Main language with a marked second language sectionMain language, plus second language and its sectionFits the main language list; note the section
Side by side translationBoth languages, equalFits both lists only if the ad can match both
Switches within paragraphsBoth languages, mixedSend to a bilingual reader before deciding
Declared language differs from detectedDetected language, with the conflict notedCheck a few more articles from the same site

What does language review look like on a real brief?

Fictional example

A gift basket company in San Antonio and El Paso

An unnamed gift basket and food gift company wants display ads beside English and Spanish articles about family celebrations, hosting and regional food in San Antonio and El Paso. It runs separate English and Spanish creative, so each page needs one clear language.

Detection labels the bulk of the candidate pages with confidence. Three kinds go to a bilingual reviewer: short recipe cards, where the text is too brief; English food columns full of Spanish dish names, which score close between the two languages; and a community site whose articles switch between English and Spanish within paragraphs.

The reviewer confirms the recipe cards as Spanish and the food columns as English. The community site is labeled mixed and kept off both single language lists, with a note that it would suit a bilingual creative if the client adds one.

  1. Kept: pages with a confirmed single language, on the matching list.
  2. Held: the mixed language community site, labeled mixed.
  3. Recorded: why each page went to a person.

How does PlacementGraph detect the language of a site?

Frequently asked questions

Can language detection tell Canadian French from European French?

Not reliably from short text. Varieties of one language are closely related, and the FastSpell authors note that identifiers struggle with closely related languages. Place names, spelling and vocabulary can hint at the variety, but a reader of the language should confirm when the plan depends on it.

Does detection work on pages with very little text?

Poorly. The W3C draft says detection is more accurate the longer and more representative the text, and that short strings may not detect well. For galleries and listings, judge the site from its longer articles, or mark the short pages as unconfirmed.

Should comments and reader posts count toward a page's language?

No. Comments can be in any language and change after publication, so they describe the readers who posted, not the article. Detect the language of the main text, and note separately if the comment section is large and in another language.

How many articles should be checked to set a site's language?

Enough to see whether the site is consistent. Check several recent articles from different sections; if they agree, label the site with that language. If they disagree, label the sections separately, since some bilingual publishers split languages by section.

Sources

  1. Strings on the Web: Language and Direction Metadata (First Public Working Draft, July 16, 2026) (opens in a new tab)W3C Internationalization Working Group
  2. Accept-Language used for locale setting (opens in a new tab)W3C Internationalization
  3. Declaring language in HTML (opens in a new tab)W3C Internationalization
  4. OpenRTB 2.6 specification (Content and Device language fields) (opens in a new tab)IAB Tech Lab
  5. Identifying Open Challenges in Language Identification (ACL 2025) (opens in a new tab)Association for Computational Linguistics
  6. Code-Switched Language Identification is Harder Than You Think (EACL 2024) (opens in a new tab)Association for Computational Linguistics
  7. FastSpell: The LangId Magic Spell (LREC-COLING 2024) (opens in a new tab)ELRA and ICCL

Researched and written by PlacementGraph Research. Read how we research, source and update these pages. Corrections: diana@placementgraph.com.

HOW AGENCIES WORK WITH US

From your first brief.
To your next campaign.

Share a brief in plain language. Get contextual websites and YouTube channels that fit it, with the evidence behind every pick and a deal ready for your usual buying platform.

  1. 01

    Share your brief

    The campaign in plain language.

  2. 02

    Get your shortlist

    The strongest contextual sites and channels, with the evidence behind each.

  3. 03

    We build the deal

    Your shortlist becomes a curated deal through our exchange partners.

  4. 04

    Activate and grow

    Buy in your usual platform. Agencies earn benefits as their investment grows.

LET’S WORK TOGETHER

Your next campaign starts here.

Your details will only be used to respond to your enquiry.

Prefer email? diana@placementgraph.com

YOUR PRIVACY

You choose whether to allow optional analytics. You can use the whole website either way.

Change or withdraw consent at any time using “Cookie preferences” in the footer. Turning analytics off stops future collection and removes this site’s analytics cookies; it does not erase information already sent. The page may refresh to apply withdrawal.