4 ms·
Sorry to be nitpicky, but this is wrong: > Have you ever wondered how Chrome knows to ask you if you’d like a web page’s content to be translated? No? Okay, ma
by chewxy 6y ago
Sorry to be nitpicky, but this is wrong:
> Have you ever wondered how Chrome knows to ask you if you’d like a web page’s content to be translated? No? Okay, maybe it’s just me then. But it’s because of the lang attribute on the <html> element.
The lang attribute is a signal to whatever's inside Chrome that detects language. Here's a simple counter example: https://twitter.com/chewxy/status/1253076770066010112 https://twitter.com/chewxy/status/1253076770066010112
The image is an SVG generated by graphviz. With no lang attribute (or even a HTML tag) Still Chrome thinks it's Luxembourgish.
Nonetheless, I appreciate the tip on the pseudoclass for lang.
- ape4 6y agoYou can set the language in the HTTP header on your server for the entire site - if that applies.
- jpxw 6y agoYep, there are also some interesting notes on this here https://superuser.com/questions/303706/how-does-chrome-know-what-language-a-page-is-in https://superuser.com/questions/303706/how-does-chrome-know-...
- cooper12 6y agoUmm, so they weren't wrong: > Chrome first checks the HTML lang attribute and if it's not present it checks the Content-Language HTTP header. Then it gets a prediction from cld3.
- saagarjha 6y agoDoes Chrome ever ignore the lang attribute?
- bryanrasmussen 6y agoI don't know if it is the case nowadays, but I seem to recall that in the old days they would check and if their model was highly predicting a language different than the one you were claiming they would serve the language they predicted. Which, even if they don't still do this, I think makes total sense and is what I would do because obviously programmers make mistakes and if your page claims to be English but your language has a high chance of being Armenian and a low chance of being English I would consider it was Armenian.
- qilo 6y agoGoogle crawler apparently ignores "lang" attribute [0]: > Google uses the visible content of your page to determine its language. We don’t use any code-level language information such as lang attributes, or the URL. But what about the Chrome browser? [0] https://support.google.com/webmasters/answer/182192?hl=en https://support.google.com/webmasters/answer/182192?hl=en
- sergeykish 6y agoYes [0]: > Chrome uses CLD3 to perform language detection on all webpages. This language detection is generally very accurate. Chrome will override the language detection if there is a language attribute on the HTML tag or a language specified in the HTTP content-language header. > However, both these signals are often incorrectly specified by the site/page, and in particular many non-English sites report the language as English (presumably based on default values from authoring tools, etc.) Currently a whitelist is used to determine if the detected language should always override the language attribute / content-language. Compact Language Detector v3 (CLD3) is a neural network model for language identification [1]. Sometimes it fails [2]. [0] https://bugs.chromium.org/p/chromium/issues/detail?id=771861 https://bugs.chromium.org/p/chromium/issues/detail?id=771861 [1] https://github.com/google/cld3 https://github.com/google/cld3 [2] https://bugs.chromium.org/p/chromium/issues/detail?id=1059237 https://bugs.chromium.org/p/chromium/issues/detail?id=105923...