-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
097fe1e
commit 9c87401
Showing
2 changed files
with
40 additions
and
5 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...ternals/packages/modules/core/src/pages/individual/components/GoogleTranslateComponent.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, { useEffect } from "react"; | ||
|
||
const GoogleTranslateComponent = ({ pageLanguage = "en" }) => { | ||
useEffect(() => { | ||
const loadGoogleTranslate = () => { | ||
// Initialize the Google Translate element | ||
window.googleTranslateElementInit = () => { | ||
new window.google.translate.TranslateElement( | ||
{ | ||
pageLanguage: pageLanguage, // Set the default language of the page | ||
layout: window.google.translate.TranslateElement.InlineLayout.SIMPLE, | ||
}, | ||
"google_translate_element" | ||
); | ||
}; | ||
|
||
// Add the Google Translate script after the page is fully loaded | ||
const script = document.createElement("script"); | ||
script.type = "text/javascript"; | ||
script.src = | ||
"//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"; | ||
document.body.appendChild(script); | ||
}; | ||
|
||
// Wait until the window is fully loaded | ||
window.onload = loadGoogleTranslate; | ||
console.info(pageLanguage,'Language Updated'); | ||
}, [pageLanguage]); | ||
|
||
return <div id="google_translate_element"></div>; | ||
}; | ||
|
||
export default GoogleTranslateComponent; |
This file contains 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