Created
January 9, 2021 07:36
-
-
Save Davisy/ea658746f6f5f55518301349f066085e to your computer and use it in GitHub Desktop.
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
from langdetect import detect | |
from google_trans_new import google_translator | |
#simple function to detect and translate text | |
def detect_and_translate(text,target_lang): | |
result_lang = detect(text) | |
if result_lang == target_lang: | |
return text | |
else: | |
translator = google_translator() | |
translate_text = translator.translate(text,lang_src=result_lang,lang_tgt=target_lang) | |
return translate_text | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment