From efdc8336788cb291fbedb080fb2376b07617c723 Mon Sep 17 00:00:00 2001 From: "Premobowei Miriki (mirikip)" Date: Wed, 28 Nov 2018 21:09:23 +0000 Subject: [PATCH] Update translation.py Comments added to give more information on certain parts of the code and one new language added to the dictionary --- translation.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/translation.py b/translation.py index 67d455a..fd26128 100644 --- a/translation.py +++ b/translation.py @@ -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))