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.
To implement the modal layout with the SELECT and OPTION markup, follow these steps:
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>
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>
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>
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>
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!