禁用 javascript 的 chrome 翻译
我正在编写一个 Google Chrome 扩展。目标页面是用俄语编写的。 Chrome 会翻译成英语。我可以看到一些不一致之处似乎与翻译有关。例如,在以下代码中,我检查是否位于特定文件夹中:
if (searchResult[0].innerHTML.indexOf("Общая папка")!=-1) alert("You are in Shared Folder."); else (alert(searchResult[0].innerHTML));
如果我多次重新加载完全相同的页面,则结果会不一致。有时它会检测到“Общая папка”,但有时却不会。当它没有检测到这个短语时,警报会说我在“共享文件夹”中,这是“Общая папка”的翻译。这里似乎没有一致性。有时我正在处理原始文本(这是首选)但有时我正在处理对我的脚本毫无用处的蹩脚翻译,因为
有人知道如何解决这个问题吗?我知道翻译适用于 HTML 的某些第二层(我没有对此进行过很好的研究)。
I am writing a Google Chrome extension. The targeted pages are written in Russian. Chrome translates to English. I can see some inconsistencies appear that seem to be linked to translation. For example, in the following code I check to see if I am in a particular folder:
if (searchResult[0].innerHTML.indexOf("Общая папка")!=-1) alert("You are in Shared Folder."); else (alert(searchResult[0].innerHTML));
If I reload the exact same page several times, the result is inconsistent. Sometimes it detects "Общая папка" but other times it does not. When it does not detect this phrase, the alert says I am in "Shared Folder" which is the translation for ""Общая папка." There appears to be no consistency here. Sometimes I am dealing with the original text (which is preferred) but sometimes I am dealing with crappy translations that are useless for my script because the translations change all the time.
Does anyone know how to fix this? Turning it off would probably fix it but actually the translations are useful and necessary for other aspects of the extension. I understand that the translation works with some secondary layer of the HTML (I have not researched this very well). Can I simply refer to the original in my script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据此答案,您可以通过放置以下元素来禁用翻译在网页的头部:
如果您需要以编程方式禁用翻译,您可以通过 JavaScript 添加该标记。
According to this answer, you can disable translation by placing the following element in the head portion of your web page:
If you needed to programmatically disable translation, you could add that tag through JavaScript.
不确定是否禁用它,但看起来在翻译后 Chrome 将
class="translated-ltr"
添加到元素,所以也许你至少可以检测到该页面已翻译,并且警告用户该扩展程序可能无法在此页面上正常工作,或者只是将其禁用。
Not sure about disabling it, but looks like after a translation Chrome adds
class="translated-ltr"
to<html>
element, so maybe you at least can detect when the page was translated and either warn a user that the extension might not work properly on this page or just disable it.