Home > Web Front-end > CSS Tutorial > How can I implement Google Translate on my website correctly using markup?

How can I implement Google Translate on my website correctly using markup?

Patricia Arquette
Release: 2024-11-01 18:41:02
Original
829 people have browsed it

How can I implement Google Translate on my website correctly using markup?

Adding Google Translate to a Web Site

Question:

I've found two code snippets for adding Google Translate to a website, but neither seems to work quite right. The first works only on a live site and doesn't allow for CSS styling, while the second doesn't work on a live site at all. How can I implement Google Translate using the second markup, which includes a selection of languages?

Answer:

Here's the markup that should work on both local and live sites:

<div id="google_translate_element"></div>
<script>
    function googleTranslateElementInit() {
        new google.translate.TranslateElement(
            {pageLanguage: 'en'},
            'google_translate_element'
        );
    }
</script>
<script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
Copy after login

This markup includes both the required elements and the initialization script to enable the Google Translate functionality. It should work on both local and live sites, allowing you to target and style the translation widget using CSS.

The above is the detailed content of How can I implement Google Translate on my website correctly using markup?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template