Home  >  Article  >  Web Front-end  >  How can I implement a customizable Google Translate modal layout on my website?

How can I implement a customizable Google Translate modal layout on my website?

Susan Sarandon
Susan SarandonOriginal
2024-11-01 15:03:31348browse

How can I implement a customizable Google Translate modal layout on my website?

Adding Google Translate to Your Website - Customizing the Interface

When integrating Google Translate into your website, you have two options: the basic inline layout or the more customizable modal layout. The code you presented from Google Translate provides the inline layout, but if you prefer the modal layout, you can use the code from the html-5-tutorial website.

Implementing the Modal Layout

To implement the modal layout with the SELECT and OPTION markup, follow these steps:

  1. Add the Google Translate code: Include the following code in the section of your HTML document:

    <code class="html"><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></code>
  2. Create a DIV container: Add the following DIV to your HTML document, wherever you want the modal to appear:

    <code class="html"><div class="translate">
        <div id="google_translate_element"></div>
    </div></code>
  3. Customize the layout (optional): You can customize the appearance of the modal by adding CSS styles to the .translate class. For example:

    <code class="css">.translate {
        position: absolute;
        top: 100px;
        right: 0;
        z-index: 9999;
    }</code>

Removing the Basic Inline Layout

If you have already added the basic inline layout, you need to remove it to prevent conflicts with the modal layout. Find the following code in the section of your HTML document and remove it:

<code class="html"><meta name="google-translate-customization" content="9f841e7780177523-3214ceb76f765f38-gc38c6fe6f9d06436-c"></code>

Note:

  • The modal layout requires JavaScript to function.
  • You may need to adjust the CSS styles to fit the design of your website.

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

Statement:
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