Home > Article > Web Front-end > How can I implement Google Translate on my website correctly using markup?
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>
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!