临时删除HTML从字符串谷歌翻译API,以降低成本 [英] Temporary removal of HTML from string for Google Translate API to reduce cost

查看:227
本文介绍了临时删除HTML从字符串谷歌翻译API,以降低成本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来翻译使用的我们付出了谷歌API的一些细节。细节包含HTML,和谷歌收费的每个字符。我不希望发送完整的内容,但只有英文文本代替,在卸下HTML。我可以删除HTML标签和使用PHP功能的实体,但我的英文内容放回HTML标签转换为正确的显示了。它还将包括CSS。

I have to translate some details using a Google API which we're paying for. The details contain HTML, and Google charges for each character. I don't want to send the complete content, but only the English text instead, with the HTML removed. I can remove HTML tags and entities using PHP functions, but I have to place the English content back in the HTML tags after translation for proper display. It will also include CSS.

例如:

<strong>This is a test</strong><br /> &nbsp; <custom tag>This is a test</custom tag><br />

翻译西班牙语后,我需要:

After translation to Spanish I need:

<strong>Translated content </strong><br /> &nbsp; <p>Translated content </p><br />

我如何preserve的HTML格式进行发送HTML的API?

How can I preserve the HTML format with out sending HTML to the API?

推荐答案

哈哈,我也有这个问题。但它已经在不久前...

Haha, I also had that problem. But it has been while ago...

我想,有一个问题是 - 由于翻译自然 - 一些sentenceparts被swaped。所以,我是不是能够适应这些标签,在同一位置,第一。但我认为有一种方式来获得从translationprocess一些元数据,都可以看到该判决的一部分已经转移到一个新的位置,什么内容是......我知道,我解决了它最后。但我不能记得如何:(

I think, there was a problem were - due to translation-nature - some sentenceparts were swaped. So I was not able to fit the tags in at the same position, first. But I think there was a way to get some metadata from the translationprocess, were you can see which part of the sentence have moved to a new position and what the content was... I know, I solved it finally. But I cant recall how :(

如果每一个字的翻​​译后再次发生同样的地方,你可以先用空格或htmltag所有单词分成数组,并记住每个HTML标签是和重新应用转换后...

If every word takes the same place again after translation, you could first separate all words by whitespace OR htmltag into an array and remember where each HTML-tag was and reapply that after translation...

这篇关于临时删除HTML从字符串谷歌翻译API,以降低成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆