HTML 块的机器翻译
PHP 中是否有任何 API(如谷歌翻译 api)允许翻译 HTML 块并仅翻译 html 中的文本?
Is there any API (like google translation api) in PHP which allows to translate HTML blocks and translate only text out of the html ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Microsoft 的翻译 API 将在维护 HTML 标签的同时进行翻译。
该 API 记录在此处。它具有 REST 和 WSDL 接口。
我倾向于将 WSDL 接口与 PHP 的 SoapClient 库一起使用。这里有一些代码向您展示如何使用它。
您需要向 Microsoft 注册您自己的应用程序 ID,并在每个请求中传递该 ID。您可以在此处注册。
我建议不要删除标签,翻译然后重新插入标签。由于您无法保证翻译中保留字数和顺序,因此很难知道将标签放置在翻译文本中的位置。最好让 MT 引擎处理标签。
Microsoft's translation API will translate while maintaining HTML tags.
The API is documented here. It has both a REST and WSDL interface.
I tend to use the WSDL interface with PHP's SoapClient library. Here is some code to show you how to use it.
You'll need to register with Microsoft for your own application ID which you pass up with each request. You can register here.
I would advise against stripping out tags, translating and then re-inserting the tags. Since you have no guarantee that word number and order is preserved in the translation it makes it very difficult to know where to place the tags in the translated text. Better to have the MT engine handle the tags.
无法完美地回答您的问题,但如果您希望从 html 中获取文本,即在网站上爬行文本,您需要一个 php 爬虫脚本:
http://forums.digitalpoint.com/showthread.php?t=708122
但如果要剥离 html 并仅获取文本,您可以使用 PHP 的:
strip_tags 函数。
但如果你的意思是要获取特定的文本片段,您可以使用正则表达式:
http://www.regular-expressions.info/
Could not get your question perfectly but if you are looking to get text out of html, sort of crawling text on a site, you need a php crawler script:
http://forums.digitalpoint.com/showthread.php?t=708122
But if meant to strip html and get only text, you can use PHP's:
strip_tags function.
But if you meant to get specific piece of text, you could use regular expressions:
http://www.regular-expressions.info/
这是另一种选择:
按照以下说明将您的网站翻译成其他语言。
该网页应该有微软的翻译器,可以用来将页面翻译成不同的语言。
Here is another option:
Follow these directions to translate your website into a different language.
The Web page should have Microsoft's translator, which can be used to translate the page into a different language.
使用正则表达式,PHP 支持它们。 Regexlib 有一个很好的库,其中包含您可以调整的各种预先编写的正则表达式。
Use Regular Expressions, PHP supports them. Regexlib has a nice library of various pre-written regexes you can adapt.