Skip to content

Commit

Permalink
Multilang supp Addn PR ( #141 ) from sezallagwal/add/gtranslator
Browse files Browse the repository at this point in the history
added multilanguage support
  • Loading branch information
4darsh-Dev authored Oct 28, 2024
2 parents 6c17f03 + 282584c commit 222979d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
16 changes: 15 additions & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>

<div class="gtranslate_wrapper"></div>

<script>
window.gtranslateSettings = {
default_language: 'en',
detect_browser_language: true,
wrapper_selector: '.gtranslate_wrapper',
}
</script>

<script
src="https://cdn.gtranslate.net/widgets/latest/float.js"
defer
></script>
</body>
<head></head>
</html>
6 changes: 5 additions & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import { BrowserRouter, Route, Routes } from 'react-router-dom';
import { useEffect, useState } from 'react';
import HomePage from './pages/HomePage';
Expand All @@ -11,7 +12,9 @@ import CreateNFT from './pages/CreateNFTPage';
import NotFoundPage from './components/NotFoundPage';
import Footer from './components/Footer';
import MyChatbot from './Chatbot';
import CustomCursor from './components/CustomCursor'; // Import CustomCursor component
import CustomCursor from './components/CustomCursor';
import GTranslateLoader from './components/GTranslateLoader'


function App() {
const [wallet, setWallet] = useState(null);
Expand Down Expand Up @@ -53,6 +56,7 @@ function App() {
<MyChatbot />
<Footer />
</div>
<GTranslateLoader />
</BrowserRouter>
);
}
Expand Down
31 changes: 31 additions & 0 deletions frontend/src/components/GTranslateLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use client";

import { useEffect } from "react";

export default function GTranslateLoader() {
useEffect(() => {
// Create the inline script for gtranslateSettings
const gtranslateSettingsScript = document.createElement("script");
gtranslateSettingsScript.innerHTML = `
window.gtranslateSettings = {
default_language: "en",
detect_browser_language: true,
wrapper_selector: ".gtranslate_wrapper"
};
`;
document.body.appendChild(gtranslateSettingsScript);

// Load the Google Translate widget script
const gtranslateLibraryScript = document.createElement("script");
gtranslateLibraryScript.src = "https://cdn.gtranslate.net/widgets/latest/float.js";
gtranslateLibraryScript.defer = true;
document.body.appendChild(gtranslateLibraryScript);

return () => {
document.body.removeChild(gtranslateSettingsScript);
document.body.removeChild(gtranslateLibraryScript);
};
}, []);

return null;
}

0 comments on commit 222979d

Please sign in to comment.