forked from dhairyagothi/StationGuide
-
Notifications
You must be signed in to change notification settings - Fork 0
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
3064aaf
commit f54a52e
Showing
6 changed files
with
172 additions
and
17 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,72 @@ | ||
#languageIcon { | ||
position: fixed; | ||
top: 70px; | ||
left: 20px; | ||
--tw-bg-opacity: 1; | ||
background-color: rgb(59 130 246 / var(--tw-bg-opacity)); | ||
color: white; | ||
border-radius: 50%; | ||
width: 50px; | ||
height: 50px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
cursor: pointer; | ||
z-index: 999; | ||
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1); | ||
transition: background-color 0.3s ease-in-out; | ||
} | ||
|
||
#languageIcon:hover { | ||
background-color: #2563eb; | ||
} | ||
|
||
#google_translate_modal { | ||
display: flex; | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: rgba(0, 0, 0, 0.5); | ||
justify-content: center; | ||
align-items: center; | ||
z-index: 1000; | ||
} | ||
|
||
.modal-content { | ||
background-color: #4d90fe; | ||
padding: 20px; | ||
border-radius: 8px; | ||
box-shadow: 0px 8px 12px rgba(0, 0, 0, 0.2); | ||
position: relative; | ||
width: 80%; | ||
max-width: 500px; | ||
padding: 10px 15px; | ||
color: #fff; | ||
font-family: 'Arial', sans-serif; | ||
font-size: 14px; | ||
cursor: pointer; | ||
} | ||
|
||
.close-btn { | ||
position: absolute; | ||
top: 10px; | ||
right: 10px; | ||
background-color: #ff0909; | ||
color: white; | ||
border: none; | ||
border-radius: 50%; | ||
width: 30px; | ||
height: 30px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
cursor: pointer; | ||
z-index: 1001; | ||
} | ||
|
||
#google_translate_element { | ||
margin-top: 20px; | ||
text-align: center; | ||
} |
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,65 @@ | ||
import React, { useState } from 'react'; | ||
import translate from 'google-translate-api-x'; // Importing google-translate-api-x | ||
import './language.css'; // Assuming you have your styles in this file | ||
|
||
const Language = () => { | ||
const [modalVisible, setModalVisible] = useState(false); | ||
const [languageCode, setLanguageCode] = useState('en'); // Default language is English | ||
|
||
// Function to handle language selection | ||
const handleLanguageChange = async (e) => { | ||
const selectedLanguage = e.target.value; | ||
setLanguageCode(selectedLanguage); | ||
|
||
// Get all elements that need translation (for simplicity, we assume all text elements) | ||
const elementsToTranslate = document.querySelectorAll('[data-translate]'); | ||
|
||
elementsToTranslate.forEach(async (element) => { | ||
try { | ||
const originalText = element.getAttribute('data-original-text') || element.innerText; | ||
element.setAttribute('data-original-text', originalText); // Store original text | ||
const res = await translate(originalText, { to: selectedLanguage }); | ||
element.innerText = res.text; // Set translated text | ||
} catch (error) { | ||
console.error('Translation error:', error); | ||
} | ||
}); | ||
}; | ||
|
||
// Function to toggle modal visibility | ||
const toggleModal = () => { | ||
setModalVisible(!modalVisible); | ||
}; | ||
|
||
return ( | ||
<> | ||
{/* Language Icon */} | ||
<div id="languageIcon" title="Change Language" onClick={toggleModal}> | ||
🌐 | ||
</div> | ||
|
||
{/* Modal to select language */} | ||
{modalVisible && ( | ||
<div id="google_translate_modal" className="flex" onClick={toggleModal}> | ||
<div className="modal-content" onClick={(e) => e.stopPropagation()}> | ||
{/* Close Button */} | ||
<button className="close-btn" onClick={toggleModal}>✖</button> | ||
|
||
{/* Language Selection */} | ||
<h3>Select Language</h3> | ||
<select value={languageCode} onChange={handleLanguageChange} className='black'> | ||
<option value="en">English</option> | ||
<option value="es">Spanish</option> | ||
<option value="fr">French</option> | ||
<option value="de">German</option> | ||
<option value="hi">Hindi</option> | ||
{/* Add more language options as needed */} | ||
</select> | ||
</div> | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default Language; |