-
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.
Merge pull request #1 from forkimenjeckayang/develop
Merging Chnages in Develop to main
- Loading branch information
Showing
7 changed files
with
95 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# language_translator_extension | ||
About A web browser extension which can be used to translate from one language to another and supports speech recognition be it as input and output | ||
|
||
A web browser extension which can be used to translate from one language to another and supports speech recognition be it as input and output |
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 |
---|---|---|
@@ -1,28 +1 @@ | ||
// Create context menu item | ||
chrome.contextMenus.create({ | ||
id: "translateText", | ||
title: "Translate with Language Translator Extension", | ||
contexts: ["selection"] // Show context menu item when text is selected | ||
}); | ||
|
||
// Add click event listener for context menu item | ||
chrome.contextMenus.onClicked.addListener((info, tab) => { | ||
if (info.menuItemId === "translateText" && info.selectionText) { | ||
// Send selected text to the popup for translation | ||
chrome.runtime.sendMessage({ type: "translateFromContextMenu", text: info.selectionText }); | ||
} | ||
}); | ||
|
||
// Add listener for messages from content script | ||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { | ||
if (message.type === "textSelected" && message.text) { | ||
// Create context menu item dynamically for selected text | ||
chrome.contextMenus.create({ | ||
id: "translateText", | ||
title: `Translate "${message.text}" with Language Translator Extension`, | ||
contexts: ["selection"] | ||
}); | ||
} | ||
}); | ||
|
||
|
||
// still to work on this in upcoming version |
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 |
---|---|---|
@@ -1,24 +1,23 @@ | ||
{ | ||
"manifest_version": 3, | ||
"name": "Language Translator", | ||
"version": "1.0", | ||
"description": "Translate text to different languages.", | ||
"permissions": ["activeTab", "contextMenus"], | ||
"action": { | ||
"default_popup": "popup.html", | ||
"default_icon": { | ||
"16": "icons/icon16.png", | ||
"48": "icons/icon48.png", | ||
"128": "icons/icon128.png" | ||
} | ||
}, | ||
"icons": { | ||
"16": "icons/icon16.png", | ||
"manifest_version": 3, | ||
"name": "Language Translator", | ||
"version": "1.0", | ||
"description": "Translate text to different languages.", | ||
"permissions": ["activeTab", "contextMenus"], | ||
"action": { | ||
"default_popup": "popup.html", | ||
"default_icon": { | ||
"16": "icons/logo.jpg", | ||
"48": "icons/icon48.png", | ||
"128": "icons/icon128.png" | ||
}, | ||
"background": { | ||
"service_worker": "background.js" | ||
} | ||
}, | ||
"icons": { | ||
"16": "icons/logo.jpg", | ||
"48": "icons/icon48.png", | ||
"128": "icons/icon128.png" | ||
}, | ||
"background": { | ||
"service_worker": "background.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
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 |
---|---|---|
@@ -1,40 +1,42 @@ | ||
document.getElementById('translateButton').addEventListener('click', function() { | ||
const inputText = document.getElementById('inputText').value; | ||
const targetLanguage = document.getElementById('languageSelect').value; | ||
const translatedTextElem = document.getElementById('translatedText'); | ||
document.addEventListener('DOMContentLoaded', function() { | ||
document.getElementById('translateButton').addEventListener('click', function() { | ||
const inputText = document.getElementById('inputText').value; | ||
const targetLanguage = document.getElementById('languageSelect').value; | ||
const translatedTextElem = document.getElementById('translatedText'); | ||
|
||
// Clear previous translated text | ||
translatedTextElem.innerText = ''; | ||
// Clear previous translated text | ||
translatedTextElem.innerText = ''; | ||
|
||
// Show loading indicator | ||
translatedTextElem.innerText = 'Translating...'; | ||
// Show loading indicator | ||
translatedTextElem.innerText = 'Translating...'; | ||
|
||
const url = 'http://localhost:5000/translate'; | ||
const url = 'http://44.203.140.162:5000/translate'; | ||
|
||
const data = { | ||
q: inputText, | ||
target: targetLanguage, | ||
source: 'auto' // Automatically detect the source language | ||
}; | ||
const data = { | ||
q: inputText, | ||
target: targetLanguage, | ||
source: 'auto' // Automatically detect the source language | ||
}; | ||
|
||
fetch(url, { | ||
method: 'POST', | ||
body: JSON.stringify(data), | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
if (data.translatedText) { | ||
translatedTextElem.innerText = data.translatedText; | ||
} else { | ||
translatedTextElem.innerText = 'Translation error. Please try again.'; | ||
} | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
translatedTextElem.innerText = 'An error occurred. Please try again later.'; | ||
fetch(url, { | ||
method: 'POST', | ||
body: JSON.stringify(data), | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
if (data.translatedText) { | ||
translatedTextElem.innerText = data.translatedText; | ||
} else { | ||
translatedTextElem.innerText = 'Translation error. Please try again.'; | ||
} | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
translatedTextElem.innerText = 'An error occurred. Please try again later.'; | ||
}); | ||
}); | ||
}); | ||
|
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