diff --git a/frontend/src/components/GoogleTranslate.jsx b/frontend/src/components/GoogleTranslate.jsx new file mode 100644 index 00000000..4294fab9 --- /dev/null +++ b/frontend/src/components/GoogleTranslate.jsx @@ -0,0 +1,109 @@ +import React, { useEffect } from "react"; +import { useState } from "react"; + +const GoogleTranslate = () => { + const [isVisible,setIsVisible] = useState(true); + + useEffect(() => { + window.googleTranslateInit = () => { + if (!window.google?.translate?.TranslateElement) { + setTimeout(window.googleTranslateInit, 100); + } else { + new window.google.translate.TranslateElement({ + pageLanguage: 'en', + includedLanguages: 'en,hi,pa,sa,mr,ur,bn,es,ja,ko,zh-CN,es,nl,fr,de,it,ta,te', + layout: window.google.translate.TranslateElement.InlineLayout.HORIZONTAL, + defaultLanguage: 'en', + autoDisplay: false, + }, 'google_element'); + } + }; + + const loadGoogleTranslateScript = () => { + if (!document.getElementById("google_translate_script")) { + const script = document.createElement("script"); + script.type = "text/javascript"; + script.src = "https://translate.google.com/translate_a/element.js?cb=googleTranslateInit"; + script.id = "google_translate_script"; + script.onerror = () => console.error('Error loading Google Translate script'); + document.body.appendChild(script); + } + }; + + loadGoogleTranslateScript(); + + if (window.google && window.google.translate) { + window.googleTranslateInit(); + } + + const handleScroll = () => { + setIsVisible(window.scrollY < 100); // Adjust the scroll amount as needed + }; + + window.addEventListener('scroll', handleScroll); + + return () => { + window.removeEventListener('scroll', handleScroll); + }; + }, []); + + return ( +