如何加快谷歌翻译速度
我有一个包含 70000 个字符的网页。如您所知,通过 Google API 进行翻译时,一次最多只能发送 5000 个字符。这意味着我必须向 Google 发送数据 14 次 (70000/5000),这需要很多时间,然后我的页面才会显示。有没有办法加快这个过程?
谢谢
I have a web page that has 70000 characters. As you know when doing translation through Google API you can only send up to 5000 characters at a time. Which means I have to send data to Google 14 times (70000/5000) which takes a lot of time and then my page is displayed. Is there a way to speed up the process?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您尝试过缓存翻译吗?
have you tried caching the translation?
如果您使用某些 AJAX 框架(您没有提及您的网页是使用 c# 创建的),那么您可以通过 AJAX 框架进行 API 调用来加快速度。
它看起来像这样(伪代码,因为我们不知道您在使用什么):
这样用户将立即看到页面,并且还将看到翻译在处理过程中逐段出现,而不必等到最后。
If you were using some AJAX framework (you don't mention what your web page is created with eg c#) then you can make it faster by making the API call via the AJAX framework.
It would look something like this (psuedo-code since we don't know what you are using):
This way the user will see the page immediately, and will also see the translation appear piece by piece as it is processsed instead of having to wait until the end.
我最好的选择是用一种语言生成一个页面,然后要求谷歌通过 HTTP 翻译它并将结果显示为您自己的结果,以使其对用户来说是无缝的。我相信这就是谷歌浏览器在翻译网页时所做的事情。
让 Google 翻译整个网页的 URL 示例:
http://translate.google.com/translate?hl=en&sl=ru&tl=en&u=http%3A%2F%2Flinux.org.ru %2F
当然,如果页面内容不经常更改,另一种选择是使用 Google Translate API 并缓存结果。
My best bet would be to generate a page in one language, then ask google to translate it trough HTTP and display result as your own, to make it seamless for user. I believe that is what Google Chrome does when translating web pages.
Example of URL that makes Google translate the whole web page:
http://translate.google.com/translate?hl=en&sl=ru&tl=en&u=http%3A%2F%2Flinux.org.ru%2F
Of course, another option is to use Google Translate API and cache result if page content is not changing frequently.
转到 Google 中的 Javascript 文件,它还会引导您找到 CSS 文件,创建一个或两个文件,或者您可以将 CSS 添加到您自己的文件中,现在在您的网站上自己的目录中创建 Javascript 页面。每隔几秒或几分钟编写一段代码来更新 Javascript 代码,这将使转换更快,只需刷新他们提供的内容..玩得开心:)最终你也可以同时发送请求time 作为第一个在 char 5000 之后翻译的时间,这应该相对容易做到。
go to the Javascript file in Google, it will lead you also to the CSS file, make a file or perhaps two, or you may be able to add CSS to your own, now make Javascript page on your web site in own directory. make a nip of code to update the Javascript code every so many seconds or minutes, and this will make the transition much faster, just by refreshing the content they give.. have fun :) also ultimately you can also send a request at the same time as the first one to translate after char 5000 which should be relatively easy to do.