Google翻译-禁止翻译部分文字 [英] Google translate - Disable translating of a part of my text
问题描述
我正在管理页面上为博客创建帖子.我有一个法国的textarea和一个英语的textarea.因此,对于那些无法自己翻译的人,我创建了一个按钮与google一起翻译":
I'm working on an admin page to create post for a blog. I have a french textarea and an english textarea. So, for those who cannot translate by there own, I created a button "translate with google":
<a id="tr_textefr" href="http://translate.google.fr/#fr/en/" target="_blank">
Traduire avec Google</a>
我的法语textarea具有一个称为onkeyup的javascript函数:
And my french textarea has a javascript function called onkeyup :
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);
}
例如,如果我写"Voulez-vous beder avec moi ce soir?",它将更改" http://translate.google.fr/#fr/zh-CN/Voulez-vous 沙发avec moi ce soir吗?".链接将重定向到我的文字的翻译版本(由Google翻译).
For exemple, if I write "Voulez-vous coucher avec moi ce soir ?", it will change the href attribute for "http://translate.google.fr/#fr/en/Voulez-vous coucher avec moi ce soir ?". The link will redirect at the translated version of my text (by google translate).
顺便说一下,此代码可以正常工作.问题是,有时我的文本中会包含bbcode:"Voulez-vous [b] coucher [/b] avec moi ce soir吗?".
This code works fine by the way. The thing is that I could have sometimes bbcode inside my text: "Voulez-vous [b]coucher[/b] avec moi ce soir ?".
那么,谷歌翻译有一种方法可以禁止某些单词或句子的翻译吗?例如,我不想翻译两个@之间的单词:"Voulez-vous @ [b] @coucher @ [/b] @ avec moi ce soir吗?"
So, is there a way with google translate to disable translating of some words or sentences ? For exemple, I don't wanna translate the words between two @ : "Voulez-vous @[b]@coucher@[/b]@ avec moi ce soir ?"
推荐答案
编辑(2020年9月)::似乎对某些API进行了更改后,该解决方案不再适用(至少在网络上)
Edit (Sep. 2020): Seems that with some API changes this solution is not applicable anymore (at least on the web).
可以通过将字符串的某些部分包装在具有特定类值的< span>
标记中来保护翻译的一部分(如
Protecting parts of the string from translation is possible by wrapping them in a <span>
tag with a specific class value (as explained here):
<span class="notranslate">[bold]</span>
此外,如果您不介意支付小笔费用(每100万个字符20美元),那么Google Translate API将为您提供更大的灵活性.
Also, Google Translate API will provide you with more flexibility if you don't mind paying a small fee ($20 per 1 M characters).
这篇关于Google翻译-禁止翻译部分文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!