Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions final_project/machinetranslation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import translator
14 changes: 14 additions & 0 deletions final_project/machinetranslation/tests/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#import unittest

#from machinetranslation import english_to_french, french_to_english
##class TestEnglishToFrench(unittest.TestCase):
# def test1(self):
#self.assertEqual(english_to_french("Hi"), "Bonjour")
#self.assertEqual(english_to_french("Eating"), "Mange")

#class TestFrenchToEnglish(unittest.TestCase):
#def test1(self):
# self.assertEqual(french_to_english("Bonjour"), "Hello")
# self.assertEqual(french_to_english("Manger"), "Eating")

#unittest.main()
12 changes: 12 additions & 0 deletions final_project/machinetranslation/translator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"Contains the translation methods"
from deep_translator import MyMemoryTranslator

def english_to_french(english_text):
"Translates from english to french"
french_text = MyMemoryTranslator(source='english', target='french').translate(english_text)
return french_text

def french_to_english(french_text):
"Translates from french to english"
english_text = MyMemoryTranslator(source='french', target='english').translate(french_text)
return english_text
10 changes: 5 additions & 5 deletions final_project/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
@app.route("/englishToFrench")
def englishToFrench():
textToTranslate = request.args.get('textToTranslate')
# Write your code here
return "Translated text to French"
translatedText = translator.english_to_french(textToTranslate)
return translatedText

@app.route("/frenchToEnglish")
def frenchToEnglish():
textToTranslate = request.args.get('textToTranslate')
# Write your code here
return "Translated text to English"
translatedText = translator.french_to_english(textToTranslate)
return translatedText

@app.route("/")
def renderIndexPage():
# Write the code to render template
return render_template("index.html")

if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)