谷歌翻译 - 禁止翻译我的部分文字

pmr*_*ule 13 google-translate

我正在创建一个管理页面来为博客创建帖子.我有一个法语textarea和一个英语textarea.所以,对于那些不能自己翻译的人,我创建了一个"与谷歌翻译"的按钮:

<a id="tr_textefr" href="http://translate.google.fr/#fr/en/" target="_blank">
Traduire avec Google</a>
Run Code Online (Sandbox Code Playgroud)

我的法语textarea有一个名为onkeyup的javascript函数:

function translate(what){
var button = "tr_" + what;
var textarea = document.getElementById(what);
var google = "http://translate.google.fr/#fr/en/" + textarea.value;

document.getElementById(button).setAttribute('href', google);
}
Run Code Online (Sandbox Code Playgroud)

例如,如果我写"Voulez-vous coucher avec moi ce soir?",它将改变" http://translate.google.fr/#fr/en/Voulez-vous coucher avec moi ce soir?"的href属性? ".该链接将重定向到我的文本的翻译版本(通过谷歌翻译).

顺便说一句,这段代码很好用.问题是我的文本中有时会出现bbcode:"Voulez-vous [b] coucher [/ b] avec moi ce soir?".

那么,谷歌翻译有没有办法禁用某些单词或句子的翻译?例如,我不想翻译两个@之间的单词:"Voulez-vous @ [b] @coucher @ [/ b] @ avec moi ce soir?"

She*_*vin 17

从翻译保护部分字符串可以通过在包装他们<span>有一个特定的类值标签(如解释在这里):

<span class="notranslate">[bold]</span>
Run Code Online (Sandbox Code Playgroud)

示例:http://goo.gl/9JkhA

此外,如果您不介意支付少量费用(每1 M字符20美元),Google Translate API将为您提供更大的灵活性.

  • https://translate.google.com/#view=home&amp;op=translate&amp;sl=en&amp;tl=hi&amp;text=%3Cp%3Emy%20text%20to%20translate%3Cspan%20class%3D%22notranslate%22%3E%5Bhello%20this%20is% 20a%20test%5D%3C%2Fspan%3E%20%3C%2Fp%3E 检查这个,由于某些原因它对我也不起作用。 (3认同)
  • 我找不到所说的灵活性,但 `&lt;span&gt;` 技巧有效。不过,如果您可以在没有标记的情况下取回翻译后的文本,那就太好了。 (2认同)
  • 看来现在只要支付少量费用就可以使用Google Translate API了。您能解释一下 API 改进后的解决方案是什么吗? (2认同)

Mak*_*ane 5

只需class="notranslate"在需要的地方添加notranslate类,Google翻译器就不会碰它。.https ://cloud.google.com/translate/v2/faq#technical