Skip to content
Permalink
Browse files
Update translation.py
Comments added to give more information on certain parts of the code and one new language added to the dictionary
  • Loading branch information
mirikip committed Nov 28, 2018
1 parent 3a73bf3 commit efdc8336788cb291fbedb080fb2376b07617c723
Showing 1 changed file with 7 additions and 1 deletion.
@@ -1,17 +1,23 @@
from translate import Translator

##DO NOT MODIFY THIS DICTIONARY##
#Dictionary created contains languages supported by the translate api and their respective language codes
#List of acceptable language codes for source and target languages
languages = dict([('amharic','am'),('arabic','ar'),('basque','eu'),('bengali','bn'),('english', 'en'),('portuguese', 'pt'),
('bulgarian', 'bg'),('catalan', 'ca'),('cherokee', 'chr'),('croatian', 'hr'),('czech', 'cs'),('danish','da'),('dutch', 'nl'),('estonian', 'et'),
('filipino','fil'),('finnish','fi'),('french','fr'),('german','de'),('greek', 'el'),('gujarati','gu'),('hebrew','iw'),('hindi','hi'),
('hungarian', 'hu'),('icelandic','is'),('indonesian','id'),('italian', 'it'),('japanese','ja'),('kannada','kn'),('korean', 'ko'),('latvian','lv'),
('lithuanian','lt'),('malay', 'ms'),('malayalam', 'ml'),('marathi','mr'),('norwegian', 'no'),('polish','pl'),('romanian','ro'),('russian','ru'),
('serbian', 'sr'),('chinese' ,'zh-CN'),('slovak', 'sk'),('slovenian', 'sl'),('spanish','es'),('swahili', 'sw'),('swedish','sv'),('tamil','ta'),
('telugu','te'),('thai','th'),('turkish','tr'),('urdu', 'ur'),('ukrainian', 'uk'),('vietnamese','vi'),('welsh', 'cy')])
('telugu','te'),('thai','th'),('turkish','tr'),('urdu', 'ur'),('ukrainian', 'uk'),('vietnamese','vi'),('welsh', 'cy'),('yoruba','yo')])

def translate(text):
lang = input("What language will you like to translate to? ").lower()
if lang in languages:
fromEnglish = input("Are you translating from english? ").lower()
# Allows users to input the language they want to translate to and from
# It fetches the corresponding language code using the language as the key from the above dictionary
# it then returns the url encoded string that will be pushed to the translation server for parsing
if "yes" in fromEnglish:
translator = Translator(to_lang=languages[lang])
print(translator.translate(text))

0 comments on commit efdc833

Please sign in to comment.