Best way of using google translation by Python

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

提交回复
热议问题