如何在Chrome中从HTML禁用Google翻译

我刚为一家法国餐厅做了一个网站。网站是英文的,但我猜网站上有足够的法语(菜单项目的标签图片),如果使用Chrome浏览器,可以提示访问者翻译网站。

我可以在HTML中添加一些东西来防止Chrome要求翻译页面吗?我假设它是类似于<html lang="en">的东西,但这不起作用。

有什么想法吗?

谢谢

163064 次浏览

New Answer

Add translate="no" to your <html> tag, like so:

<html translate="no">

MDN Reference


Old Answer

(This should still work but is less desirable because it is Google-specific, and there are other translation services out there.)

Add this tag in between <head> and </head>:

<meta name="google" content="notranslate">

Documentation reference

The meta tag in the <head> didn't work for me, but

class="notranslate"

added to a parent div (or even <body>) did work and allows more precise control of the content you don't want to be translated.

Disable google translate on your website

Add this to your <head></head>:

<meta name="google" content="notranslate" />

FYI, if you want something that will work for all content in your site (including that which is not HTML), you can set the Content-Language header in your response (source) to the appropriate language, (in my case, en-US).

This has the benefit here is that it will "disable" the offer to translate the page for you (because it will know the source language correctly), but for other, non-native readers, they will still have the option to translate your site into their own language, and it will work correctly.

(Also for my use case, where Chrome was offering to translate well formatted JSON from latin to English, that BS goes away.)

So for the ultimate solution I made;

<!DOCTYPE html>
<html lang="en" class="notranslate" translate="no">
<head>
<meta name="google" content="notranslate" />
</head>
<body>
...
</body>
</html>

This worked for me.

Add this in your <head>:

<meta name="google" content="notranslate" />

and change your <html> tag to

<html lang="en" class="notranslate" translate="no">

The more simple way is just adding the translate="no" proprety. This can be made in divs, text and more. Here's an example:

/* Just some basic styling */
div[translate] {
width: 50%;
border: 1px solid black;
padding: 20px;
border-radius: 7px;
text-align: center;
font-family: Arial;
}
<div style="display: flex;gap:20px;">
<div translate="no"> <!-- Disables translation -->
Enabled<br>
<b>Olá - Hello - Hola</b>
</div>
<div translate> <!-- Enables translation -->
Disabled<br>
<b>Olá - Hello - Hola</b>
</div>
</div>

Note that this example has some problems on the stackoverflow viewer.

My Windows is german in german.

I made the following experiences in Chrome: If I set

<html lang="en" translate="no">

Google Translate comes up with suggestion to translate english.

Definitely I have to omit the lang property. This works for me:

<html translate="no">

No popup is coming up and the translation icon in the URL field is no longer displayed.

Solution:

<html lang="en" class="notranslate" translate="no">    <!-- All translators -->
<head><meta name="google" content="notranslate" /> <!-- Just for google -->
</head>                                                <!-- Close head      -->

The more simple way is just adding the translate="no" proprety. This can be made in divs, text and more. Here's an example:

// Just for instructions
// Do not copy or paste
console.log("The first div don't alows translateing. But the second, alows it.")
console.log("Open the translator and see the efect.")
DIV1
<div translate="no">
Try translating me!
<b>Olá - Hello - Hola</b>
</div>
<hr> DIV2
<div translate="">
Now, you can do it!
<b>Olá - Hello - Hola</b>
</div>

Note that this example has some problems with the StackOverflow viewer.


Disclaimer: This answer is repeated, on it is on the Community Wiki.

sometimes you need to block not all html, but specific element, in such case you could add class="notranslate" only to that element. ie. <div class="notranslate"> some content </div>

The google tag for not translating the page has been updated to

<!-- opt out of translation features on all search engines that support this directive -->
<meta name="robots" content="notranslate">

or

<!-- opt out of translation features on Google -->
<meta name="googlebot" content="notranslate">```


For more info check this links:

https://developers.google.com/search/docs/crawling-indexing/special-tags

https://developers.google.com/search/docs/appearance/translated-results


Moreover, I had to update this because it was not working on Edge browser by using only translate="no" as below:

<html translate="no">

So for a full solution as mentioned here too, i had to do something like this to not translate anything from search engines

<html lang="en" class="notranslate" translate="no">
<meta name="robots" content="notranslate" />
...
</head>