1

I have a website which I manually translated in five languages, adding the button to choose the preferred one.

My problem is that sometimes Chrome offers a Translate this page option for the user's language or, depending on the settings, automatically translates it.

And since $_SERVER['HTTP_ACCEPT_LANGUAGE'] is not always 100% reliable (if not missing at all), it could happen that an user (let's say an Italian user) who opens my website in the English version, finds a non-so-accurate-google-translated page instead of the "official" italian version of the website.

Furthermore, an user with an Italian HTTP_ACCEPT_LANGUAGE could want to see the website in another language for any reason, and it's quite annoying seeing Google's popup every time you change page (even if you can Disable it for this website).

So I found these solutions: <html lang="en" translate="no"> (which does not work for some reason) and <meta name="google" content="notranslate"> (which works).

The problem is that they prevent Google from translating in ANY language, comprehending the ones not included inside my website.

So, is there a way to prevent Google (or other translators) from proposing the translation of/automatically translate my page only in some languages?

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • When you say Google you refer to Chrome browser, to search results or to something else? In those two cases translations happens per user request as far as I know. – Álvaro González May 26 '20 at 09:01
  • @ÁlvaroGonzález I was talking about Chrome (even if google search offers a translation service too). Translation happens per user request/user consent (after a popup)/automatically depending on the settings,and what I want to prevent is that popup/autotranslation which is prevented by that meta tag but for every language –  May 26 '20 at 13:33

1 Answers1

0

I would recommend to sniff the accepted languages on the server-side, then add the header dynamically in case the user uses one of the languages you "natively" support on your site.

<html>
<head>
<?php
    $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
    $acceptLang = ['it', 'en', 'fr']; // your list of supported languages
    if (in_array($lang, $acceptLang)) {
?>
<meta name="google" content="notranslate">
<?php    
    }

?>
</head>

Chrome's language detection:

Chrome uses a so-called "CLD" (Compact Language Detector, now in version 3) which scans text on a web page using a neural network to determine which language is most likely used on the rendered web page. The entire process is well documented for CLD V2 if you want to understand the entire process. If a web page does not translate in Chrome this is most likely due to Chrome not being able to properly identify the language based on the information found on the page. A possible work-around to support easier identification is to add a hidden text block containing enough text in the language of your page at the start of the page, at least it is a recommendation taken from this SO answer.

SaschaM78
  • 4,376
  • 4
  • 33
  • 42
  • Thanks, it helped with some edits! I will accept the answer if you help me finding some documentation telling when google automatically translates pages and when there's only the small icon in the corner... I couldn't find anything up to now –  May 26 '20 at 21:43
  • 1
    @Foxel I did some research and stumbled over Chrome's "CLD". The relevant parts have been added to my answer. Hope that helps :-) – SaschaM78 May 27 '20 at 08:17
  • @CBroe it seems Chrome no longer only relies on the `lang` tag, at least the comments to [this SO answer](https://stackoverflow.com/a/8852346/1178759) mention that this no longer works properly. Also have a look at the comments in the other mentioned post where people also complain the tag no longer works. – SaschaM78 May 27 '20 at 08:27
  • @SaschaM78 it helps, but it does not answer to the question "when does google automatically translate the page?". Even if it detects the right language, sometimes it doesn't offer a translation and sometimes it automatically translate everything, even if the language is included in the supported ones. –  May 27 '20 at 08:45
  • @SaschaM78 I am not sure how much of what is written there, applies here to begin with. Over there, it is about completely supressing the automatic translation, and the example has German text in a document that is marked as being in English. – CBroe May 27 '20 at 08:54
  • Perhaps explicitly letting Google know which translations exit for a specific document might make sense? https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link, with the `href` and `hreflang` attributes set - maybe that can make Google suggest the user visit the actual version in language X, instead of offering their own translation? – CBroe May 27 '20 at 08:57
  • 1
    @Foxel, Cbroe: I think we are currently mixing terms and possible solutions here. There are several ways how to tell Google (= the search engine) in which languages a page is available like described in the [Google Webmaster docs](https://support.google.com/webmasters/answer/189077?hl=en&ref_topic=2370587). Then there is Google Chrome based on the Chromium project that uses a different approach to detect the language which is described in the [Chromium Translate Design Doc](https://sites.google.com/a/chromium.org/dev/developers/design-documents/translate). – SaschaM78 May 27 '20 at 09:07
  • @CBroe I'm already using hreflang and Google Search has already correctly indexed my pages. The problem comes when an user manually chooses a language which is not its own on purpose (for any reason), and then Google continuously offers a translation to that user. The same problem occurs when PHP automatically sets the language to the first `HTTP_ACCEPT_LANGUAGE` occurrence, but it is not the first one set on Chrome browser. So a solution (apparently not possible) would have been knowing which language is set as the default one in Chrome, which could be different from `HTTP_ACCEPT_LANGUAGE` –  May 27 '20 at 14:26
  • @SaschaM78 thank you very much! I'm using Chromium so this is exacly the behavior I'm experiencing (even if I think that Chrome behaves in the same way since it derives from Chromium). I partially solved setting `notranslate` always except when the language is set on english and there's not any supported one inside `HTTP_ACCEPT_LANGUAGE`, which could be an indicator that the user is not purposely seeing the page in a non-supported language –  May 27 '20 at 14:30
  • @SaschaM78 I was kinda expecting/hoping that Chrome was smart enough to realize when there’s explicit alternate language versions provided, and would offer to switch to those then, instead of offering its own translation. But if it’s to dumb for that :-), then you’re right, this needs some sort of dynamic solution then. – CBroe May 27 '20 at 14:31
  • I totally agree, I would have also preferred to see a straightforward option to tell Chrome what to do and which language to use. But maybe the dev community does not want a web host to tell the browser which language to use and instead rely on the integrated translation engine. @Foxel good to hear that you found at least a partial solution! – SaschaM78 May 27 '20 at 14:57
  • @SaschaM78 that's better than nothing... Anyway, thanks for your support. Greetings! –  May 27 '20 at 15:57