Best way of using google translation by Python

后端 未结 6 1226
渐次进展
渐次进展 2021-02-05 03:32

I am trying to translate large number of text files from English to other several languages. And we use Python in our project, we try to use Google translation service to transl

6条回答
  •  终归单人心
    2021-02-05 04:06

    Use this This code is using google trans module which is free to use.

    NOTE - IMPORTING METHOD OF googletrans IS DIFFERENT FROM OTHER MODULES SO KINDLY WATCH THIS TUTORIAL FIRST.

    From this code you can convert any language to any language and also get pronunciation of it.

    from googletrans import Translator, LANGUAGES
    from googletrans.models import Translated
    
    lang = list(LANGUAGES.values())
    print("Welcome to Py_Guy Translate")
    input_text = input("Please Enter Your Text in english:\n")
    out_lang = input("Please enter output language name (ex.-hindi,gujarati,japanese:\n 
    ").lower()
    if out_lang not in lang:
        print("Sorry This Language is not available to translate")
    else:
        translator = Translator()
        translated = translator.translate(text=input_text, src="english",dest=out_lang)
        translated = str(translated).split(", ")
        converted = translated[2]
        pro = translated[3]
        print(converted)
        print(pro)
    

    Watch the video tutorial here to get better understanding about the code

提交回复
热议问题