Home About Me

When a Page Lies About Its Language

The first time this issue shows up, it looks less like a technical problem and more like a typo with a grudge. A page contains perfectly normal Chinese, but the text that appears on screen is strange enough that you have to read it twice to confirm it is still Chinese — just not Chinese that makes sense. The cause is usually not the text itself. It is the page’s lang attribute.

A screenshot showing garbled Chinese text

The markup below is enough to trigger it. The visible text is Chinese, while the document claims to be English:

<html lang="en-US">
    <head>
        <meta charset="utf-8">
        <!-- irrelevant tags omitted -->
    </head>
    <body>
        <p>
            一些中文文本
        </p>
    </body>
</html>

Because the browser sees en-US, its auto-translate feature treats the page as a foreign-language document. On a browser set up to translate pages automatically, the translator may attempt to translate Chinese into Chinese. Nobody needs that, but the model still produces output. The result is text that is technically in the right script and practically useless. In mild cases it slows reading; in worse cases it can shift the meaning of a sentence without the reader noticing.

The attribute in question is the one on the root element:

<html lang="语言代码">
    <!-- rest omitted -->
</html>

Its job is to state the page language and, when needed, a regional or script variant. The values come from BCP47. Simplified Chinese can be zh-Hans; if the mainland China variant needs to be explicit, zh-Hans-CN works. Some older pages also declare language through a <meta> tag, but the root lang attribute is the part that matters here.

People are fairly good at recognizing language from context. Show someone 吃葡萄不吐葡萄皮,不吃葡萄倒吐葡萄皮 and they will identify it as Simplified Chinese. Show them How are you? Fine, and you? and they will identify English. Machines have a harder time with plain text. Detecting the main language of an arbitrary string is possible, but it costs computation, sacrifices accuracy, or only produces a rough guess — for example, all-ASCII text is probably not CJK, but that does not identify the language.

HTML is not plain text, though. It carries metadata, attributes included. A parser or browser that needs to know the page language will often check whether the document has already declared one. If it has, that value is treated as the publisher’s deliberate statement: this is the primary language of the page. That is a reasonable shortcut. It is also why a wrong value is not a harmless decoration.

The auto-translator is the most visible victim. A browser that has translation enabled for major foreign languages will see en-US and act accordingly. The page’s actual language never gets a vote. What follows is a translation pass over Chinese content, with Chinese as the target. The output can look like this:

在文学匮乏的读史里面一般只有几个作家会这么写....

The exact failure depends on the translation model, but the pattern is familiar: the text stops being readable, and the reader has to guess what the original sentence meant. For anyone who relies on a screen reader, there is a second problem. Incorrect language metadata can prevent the text-to-speech system from selecting the right voice or conversion model. To most readers it may sound like a minor annoyance; to someone who depends on TTS, it is a real barrier.

Search engines are a different story. Major engines such as Google do not appear to rely on this attribute alone. Google has said it uses link hreflang to identify region-specific pages on multilingual sites, for example. That may explain why some site owners never notice the misconfiguration: the SEO penalty is not obvious, so nothing forces them to look.

How common is it? It is hard to give a precise number. In an RSS reader that aggregates personal blogs, I saw roughly one misconfigured site for every ten or twenty feeds, and those sites were triggering browser auto-translation. One had published an update the day before.

A site that published an update yesterday

A likely reason is that many blogs use open-source blogging software and themes built with an international audience in mind, and a large share of the developers behind those projects work in English-speaking regions. The default can easily end up as en even when the content is not. Fixing it is usually simple: check the theme for a shared header include, find the root lang attribute, and set it to the language the site actually publishes in.

It is a small detail. It still improves the reading experience for people who never asked to have Chinese translated into Chinese.