Best way of using google translation by Python

后端 未结 6 1205
渐次进展
渐次进展 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:02

    One of the simplest ways is to use Selenium for getting the translations of the words and phrases.

    Here is a piece of code that gets the word in English and returns the Persian (Farsi) translation. Everything is explained in the readme file on Github:

    https://github.com/mnosrati/Google-Translate-Farsi

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-02-05 04:07

    Google does in fact have an official translation API with a REST interface. You can check it out here. Note that it is a paid API with no free quota.

    0 讨论(0)
  • 2021-02-05 04:13

    Since the origin of this post, connecting to the Google Translate API has become a whole lot easier. That being said, I would still recommend connecting directly to the Google Translate API, but now through it's RapidAPI page here.

    You can find out how to obtain an API key here. Just input the API key into the API's function page on Rapid API and click TEST Function. For example, that’s what a basic english to german translation will look like:

    Just note that de is the language code for German. RapidAPI will generate a code snippet for you so you can just copy and paste the API call directly into your project.

    0 讨论(0)
  • 2021-02-05 04:15

    I made my own google translate function for python ;) try it https://github.com/mouuff/Google-Translate-API

    0 讨论(0)
  • 2021-02-05 04:16

    Try using the googletrans module. For example:

    from googletrans import Translator
    
    
    translator = Translator()  # initalize the Translator object
    translations = translator.translate(['see if this helps', 'tarun'], dest='hi')  # translate two phrases to Hindi
    for translation in translations:  # print every translation
        print(translation.text)
    
    # Output:
    # देखें कि इस मदद करता है
    # तरुण
    

    The dicts of the supported languages (106) and their ISO639-1 codes:

    import googletrans
    
    
    print(googletrans.LANGCODES)  # {language name: iso639-1 language code}
    # or
    print(googletrans.LANGUAGES)  # {iso639-1 language code: language name}
    

    See the docs for more information.

    0 讨论(0)
提交回复
热议问题