通过PHP使用Google Translate API

Note: an advanced continuation of this topic is accessible here

注意:可在此处访问该主题的高级继续

If your site serves visitors from different countries, you may already have translated all its static content into several languages. But what to do with the content posted daily by the users in comments, opinions and ratings? As this may be as valuable a part of your site as the static content, you should think of finding a way to translate it into other languages. One service that can help is, of course, Google Translate.

如果您的网站为来自不同国家/地区的访问者提供服务,则您可能已经将其所有静态内容翻译成多种语言。 但是,用户每天在评论,意见和评分中发布的内容该怎么办? 由于这可能与静态内容一样对您的网站有价值,因此您应该考虑寻找一种将其翻译成其他语言的方法。 当然,可以提供帮助的一项服务是Google Translate

After going through this tutorial you will be able to fetch translations from the Google Translate API right from your app. You will learn how to gain access to the API, how to use it and how to handle errors if they occur.

阅读完本教程后,您将可以直接从您的应用程序从Google Translate API获取翻译。 您将学习如何获得对API的访问权,如何使用它以及如何处理发生的错误。

创建一个Google API帐户 (Creating a Google API account)

In order to gain access to the Google Translate API, you will have to create a new project on the Google APIs Console which requires an active Google account. After creating a new project, just turn on Translate API on the list of all the available APIs by flicking a switch.

为了获得对Google Translate API的访问权,您将必须在Google API控制台上创建一个新项目,该项目需要一个有效的Google帐户。 创建新项目后,只需轻按一下开关即可打开所有可用API列表上的Translate API。

价钱 (Pricing)

Since the Google Translate API is a paid service, you will also need to enable billing in your project settings. To do so, click Billing in the left menu on the Google APIs Console and then Enable billing. You will be asked to enter the payment data such as your address and credit card number. Different payment options are available in various countries but credit card payment should be recognised worldwide.

由于Google Translate API是一项付费服务 ,因此您还需要在项目设置中启用结算功能。 要做到这一点,请单击在谷歌API控制台左侧菜单中选择结算 ,然后启用计费 。 系统将要求您输入付款数据,例如您的地址和信用卡号。 各个国家/地区提供不同的付款方式,但信用卡付款应在全球范围内得到认可。

At the time of writing this article, the usage fee was $20 per 1 million characters of translation or language detection. Which means that translating a user comment of 300-400 characters would cost you $0.006 – $0.008. Naturally, if you want to translate a text into more than one target language, you will have to pay separately for each translation.

在撰写本文时,使用费为每100万个翻译或语言检测字符20美元。 这意味着翻译一个300-400个字符的用户注释将花费您$ 0.006-$ 0.008。 自然地,如果您想将一种文本翻译成一种以上的目标语言,则必须为每种翻译单独付费。

If you fear getting billed too much for the translations you make, you can control the API usage in your project by setting the maximum lim

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值