Skip to content
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

Final changes #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
15 changes: 15 additions & 0 deletions final_project/machinetranslation/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unittest

from translator import english_to_french, french_to_english

class TestEnglishToFrench(unittest.TestCase):
def testE2F(self):
self.assertEqual(english_to_french('hello'), 'bonjour')
self.assertNotEqual(english_to_french('yes'), 'bonjour')

class TestFrenchToEnglish(unittest.TestCase):
def testF2E(self):
self.assertEqual(french_to_english('bonjour'), 'hello')
self.assertNotEqual(french_to_english('oui'), 'hello')

unittest.main()
15 changes: 15 additions & 0 deletions final_project/machinetranslation/tests/tests copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unittest

from translator import english_to_french, french_to_english

class TestEnglishToFrench(unittest.TestCase):
def testE2F(self):
self.assertEqual(english_to_french('hello'), 'bonjour')
self.assertNotEqual(english_to_french('yes'), 'bonjour')

class TestFrenchToEnglish(unittest.TestCase):
def testF2E(self):
self.assertEqual(french_to_english('bonjour'), 'hello')
self.assertNotEqual(french_to_english('oui'), 'hello')

unittest.main()
18 changes: 18 additions & 0 deletions final_project/machinetranslation/translator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Defines functions to translate from e2f and f2e
"""
from deep_translator import MyMemoryTranslator

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

def french_to_english(french_text):
"""
Translates french text to english
"""
english_text = MyMemoryTranslator(source='fr', target='en').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"
french_text = translator.english_to_french(textToTranslate)
return french_text

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

@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)