Created
February 12, 2021 19:00
-
-
Save huggler/a73eba0c7e0a410d5a77d2384095b68e to your computer and use it in GitHub Desktop.
Componente react GoogleTranslate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect } from "react"; | |
const GoogleTranslate = (props) => { | |
const googleTranslateElementInit = () => { | |
new window.google.translate.TranslateElement({ pageLanguage: 'pt', layout: google.translate.TranslateElement.InlineLayout.SIMPLE, includedLanguages: 'en,es,pt', autoDisplay: false, multilanguagePage: true }, 'google_translate_element') | |
} | |
useEffect(() => { | |
var addScript = document.createElement('script'); | |
addScript.setAttribute('src', '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit'); | |
document.body.appendChild(addScript); | |
window.googleTranslateElementInit = googleTranslateElementInit; | |
}, []) | |
return ( | |
<div id="google_translate_element" /> | |
); | |
}; | |
export default GoogleTranslate; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment