HTML lang attributes for a multilingual site

I have a website that uses mostly English, but also includes a significant number of Japanese.

What are the best practices for multilingual sites? Declaring two languages ​​in the html tag is not entirely accurate, and the built-in lang markup seems redundant and heavy.

How do I approach this?

+4
source share
2 answers

Use the lang attribute in the html element and / or any element containing a sentence or more in another language. You can count, for example. book title or other long phrase as a sentence. But using, say, lang=ja for any Japanese name that appears in the English text is more or less pointless if you have no practical reason for this.

Markup language has several potential uses, some of which are slowly being implemented. Search engines, as you know, do not use it, but, for example, automatic hyphenation (when calling) uses it, and some speech synthesis software has used it. If you open an HTML document in Microsoft Word, it recognizes lang markup and can run spellcheck accordingly (for supported languages).

This use of lang markup is most important in relation to the document as a whole or its main parts. The finer grained the markup, the less its potential utility becomes, as a rule, even more tedious for generation. It is not even clear whether, for example, the name of the German language should be considered as a German text in every way if it appears inside the text in English.

A special caveat: the use of lang markup can affect the choice of font if you leave it in the browser. For example, if you write I visited <span lang=ja>Yokohama</span> , which is logical (although I visited <span lang=ja-Latn>Yokohama</span> will be more accurate), you can get the word " Yokohama font other than hidden text in Firefox. The reason is because the browser uses different default fonts for different languages ​​declared in the markup. But this, of course, is not a concern if you install a common font family in CSS, as most authors do.

+2
source

inline lang markup seems redundant and heavy

Well, this is the best way to do this. You can insert a specification if you want.

0
source

Source: https://habr.com/ru/post/1398932/


All Articles