-
-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Multilingual Translator #193
Merged
RamakrushnaBiswal
merged 12 commits into
RamakrushnaBiswal:main
from
17arindam:google_translate
Oct 12, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3377604
Merge branch 'main' of https://github.com/17arindam/PlayCafe
17arindam f677f12
Merge branch 'main' of https://github.com/17arindam/PlayCafe
17arindam 8b75138
Merge branch 'main' of https://github.com/17arindam/PlayCafe
17arindam 563303e
google translater added
17arindam 6cf1ca0
fix coderabbit suggestion 1
17arindam 82e40ef
code rabbit suggestion 2
17arindam 488f68c
Merge branch 'main' of https://github.com/17arindam/PlayCafe into goo…
17arindam 8f10d6d
improved ui of google translator
17arindam d383829
Merge branch 'main' of https://github.com/17arindam/PlayCafe into goo…
17arindam afc5391
ui changed of google translate
17arindam ebd6e84
docs(contributor): contrib-readme-action has updated readme
github-actions[bot] 84fec75
Merge branch 'main' of https://github.com/17arindam/PlayCafe into goo…
17arindam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,87 @@ | ||
import React, { useEffect } from "react"; | ||
|
||
const GoogleTranslate = () => { | ||
useEffect(() => { | ||
let retryCount = 0; | ||
const maxRetries = 50; // Adjust as needed | ||
|
||
window.googleTranslateInit = () => { | ||
if (!window.google?.translate?.TranslateElement) { | ||
if (retryCount < maxRetries) { | ||
retryCount++; | ||
} else { | ||
console.error('Failed to initialize Google Translate after maximum retries.'); | ||
} | ||
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,nl,fr,de,it,ta,te', | ||
layout: window.google.translate.TranslateElement.InlineLayout.VERTICAL, | ||
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?.translate) { | ||
window.googleTranslateInit(); | ||
} | ||
|
||
return () => { | ||
// Cleanup logic if necessary | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div id="google_element" className="pl-20 md:pl-0"> | ||
<style jsx>{` | ||
.goog-te-combo { | ||
@apply w-full bg-white border border-gray-300 rounded px-2 py-1 text-sm; | ||
} | ||
.goog-te-gadget { | ||
@apply flex flex-col items-start text-xs text-gray-500; | ||
} | ||
.goog-te-gadget > div { | ||
@apply w-full mb-1; | ||
} | ||
.goog-te-gadget > span { | ||
@apply flex flex-col items-start; | ||
} | ||
.goog-te-gadget .goog-logo-link { | ||
@apply flex items-center; | ||
} | ||
.goog-te-gadget .goog-logo-link img { | ||
@apply ml-1; | ||
} | ||
.goog-te-gadget > span > a:last-child { | ||
@apply mt-[-2px]; | ||
} | ||
.goog-te-banner-frame { | ||
@apply hidden !important; | ||
} | ||
.goog-te-menu-frame { | ||
@apply max-h-96 overflow-y-auto bg-white border border-gray-300 rounded; | ||
} | ||
.skiptranslate > iframe { | ||
@apply h-0 border-none shadow-none; | ||
} | ||
`}</style> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GoogleTranslate; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add cleanup logic in the
useEffect
cleanup functionThe
useEffect
hook returns a cleanup function, but it currently contains only a placeholder comment. To prevent potential memory leaks and side effects, consider adding necessary cleanup logic when the component unmounts.For example, you might want to remove the script or clean up global functions: