EADST

Python: Google Translation API Code

Python: Google Translation API Code

import requests

def translate_text(text, target_language='zh-CN', api_key='AIxx'):
    url = "https://translation.googleapis.com/language/translate/v2"
    querystring = {
        'q': text,
        'target': target_language,
        'key': api_key # Get from GCP $300 free credit
    }

    response = requests.request("GET", url, params=querystring)

    data = json.loads(response.text)

    return data['data']['translations'][0]['translatedText']


print(translate_text("Hello")) #你好
相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
站点统计

本站现有博文266篇,共被浏览440642

本站已经建立2019天!

热门文章
文章归档
回到顶部