Html lang attribute wrong value when using "set locale from accept language header"

AI-generated summary

The discussion revolves around an issue with the lang attribute in the <html> tag when using the “set locale from accept language header” feature. guidoleenders reports that the attribute is set to the site’s default locale (“nl”) even when the Accept-Language header is set to a different language (“en”). This causes a discrepancy between the language of the content and the lang attribute.

simon points out that Google’s crawler does not set the Accept-Language header, which would seem to rule out this approach for solving the issue. However, guidoleenders corrects this, citing a Google blog post from 2015 that indicates Google does support crawling with Accept-Language.

The issue has implications for indexability, as the incorrect lang attribute may affect how search engines understand the content’s language.

We are trying to list some of our products on AppSource of Microsoft. They require an all English experience for listing. However, our forums are bilingual and I want to include a link to the English category on the AppSource listing.

We have enabled “set locale from accept language header” to allow people from India to see the secondary content in English (“Last topics” instead of “Laatste nieuwsberichten” - Dutch).

However, when testing with Postman and Accept-Language switching from “nl” to “en”, the generated HTML is incorrect:

With en:

<!DOCTYPE html>
<html lang="nl">

<head>

With nl:

<!DOCTYPE html>
<html lang="nl">

<head>

The actual labels are correctly changed from Dutch to English, but the html tag still lists the language as Dutch instead of the language of the content.

A test was also run from Locale-Adaptive Pages Testing Tool | TechnicalSEO.com with identical outcome:

It would be good for indexability when the lang attribute could be set either from the accept-language or derived from the category for Google. Please remember that Google crawls from US typically with Accept-Language set.

Just to be clear, is the issue that you are describing only happening with crawlers and API requests?

From Google’s documentation:

In addition, the crawler sends HTTP requests without setting Accept-Language in the request header.

Since Google doesn’t set the Accept-Language header, that approach isn’t going to work to solve the issue with Google.

The html tag’s lang attribute is always set to the site’s default locale. This is also the case when a user selects a locale other than the site’s default locale from their preferences page.

2 Likes

I am sorry. Maybe I pasted the wrong URL. See Crawling and indexing of locale-adaptive pages  |  Google Search Central Blog  |  Google for Developers

Since 2015 Google supports crawling with accept language.

1 Like