Python calls Google Translate API translation

Source: Internet
Author: User

1, the installation of related modules

Pip Install--upgrade Google-cloud

Or

Pip Install--upgrade google-cloud-translate


2, before invoking the API for translation, you need to install the relevant certificate

The official website provides the method to have three kinds: 1, installs the Google Cloud SDK downloading address

2, running in Google App Engine production

3, running in Google Compute Engine production

Because running locally, the first way to use, after installation there will be an automatic pop-up verification mailbox interface, if not in the Google Cloud SDK Shell run Gcloud auth application-default Login

3. Write Python program

From Google.cloud import translate
translate_client = translate. Client ()

text = U ' hello,world '
target = ' ru '

translation = Translate_client.translate (text,target_ Language=target)

print u ' text:{} '. Format (Text)
print u ' translation:{} '. Format (translation[' Translatedtext '])

If you want to translate target = ' ru ' into target = ' ZH-CN ' reprint please specify: http://blog.csdn.net/u010856630/article/details/73810718

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.