Search code examples
javascriptgoogle-translate

Google Chrome doesn't offer translation for my website


Google translation icon doens't appear on a website I'm working on, and I can't find a reason for this. Should I add a specific code to enable chrome to suggest translating it?

Please note that I don't want to add Google Chrome widget, and Chrome settings are OK.

I'd like to make Chrome suggests to translate the pages of the website.

Here's an example: https://drive.google.com/file/d/1hKlPcs_HnIXApSa7jYX1pvDZigvdh9mc/view?usp=sharing


Solution

  • You can force the Chrome Translate dialog to show up by adding the lang tag with the language. This should work as long as the user doesn't have the settings in Chrome to never translate. Some people turn off that dialog in the chrome settings because they do not want to be annoyed by the translate dialog.

    https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Language

    sample html.

    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
    <meta charset="UTF-8">
    <title>Title of the document</title>
    </head>
    <body>
    <p>这只是一个测试。</p>
    </body>
    </html>