PHP 语言转换器
我有一个脚本用于将英语文本转换为其他口语语言,并且我有一个 php 代码像这样处理它。
ini_set("max_execution_time", "300");
header('Content-Type: text/html; charset=utf-8');
require_once('googleTranslate.class.php');
$gt = new Google_Translate_API();
$title = $gt->translate($title, "en", $lang);
$keywords = $gt->translate($keywords, "en", $lang);
$body = $gt->translate($body, "en", $lang);
无论如何,当我运行这个脚本时,它在翻译大量文本之前就超时了,所以我想知道我们是否可以以某种方式一次运行一段文本?
另请注意,googleTranslate.class.php
可以从 Google 代码免费下载。
干杯
I have a script I'm using to convert English text to other spoken languages, and I have a php code handling it like so.
ini_set("max_execution_time", "300");
header('Content-Type: text/html; charset=utf-8');
require_once('googleTranslate.class.php');
$gt = new Google_Translate_API();
$title = $gt->translate($title, "en", $lang);
$keywords = $gt->translate($keywords, "en", $lang);
$body = $gt->translate($body, "en", $lang);
Anyways, when I run this script, it times out before it can translate much text at all, so I was wondering if we could run one piece at a time somehow?
Also, note that the googleTranslate.class.php
can be freely downloaded from Google Code.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,我认为你应该首先缓存结果。制作一些脚本来缓存所需语言的翻译内容。否则你很快就会达到查询限制。
Hm, well I think you shoulde cache results at first. Make some script witch caches translated content for needed languages. Else you fast will reach querys limit.
知道了。事实证明 Google Translate API 并不是正确的选择。相反,我使用的是 Bing Translate 服务。它也不限制我只能使用特定的文本长度。感谢您的帮助。 (:
Got it. Turns out Google Translate API wasn't the way to go. Instead, I'm using the Bing Translate service. It also doesn't restrict me to certain lengths of text. Thanks for the help. (: