简体   繁体   English

谷歌翻译 - 翻译回默认语言/重置翻译

[英]Google translate - translate back to default language / reset translation

I am using the Google translate dropdown on my websites and noticed that when the site is translated and than set back to the default language the words are again translated instead of the script unloading / resetting translation.我在我的网站上使用谷歌翻译下拉菜单,并注意到当网站被翻译并设置回默认语言时,单词会再次被翻译,而不是脚本卸载/重置翻译。 This makes some words really weird.这让一些词真的很奇怪。

An example is the word 'home' which I think a lot of languages use in the menu for their homepage.一个例子是“家”这个词,我认为很多语言都在他们的主页菜单中使用它。 The flow will be as following:流程如下:

  1. website is in native language (Dutch) and has 'home' in the menu.网站使用母语(荷兰语),菜单中有“家”字样。
  2. website is translated into English and the word 'home' remains 'home'网站被翻译成英文,“家”这个词仍然是“家”
  3. website is translated back into Dutch and the word 'home' becomes 'huis' (meaning house).网站被翻译回荷兰语,“家”这个词变成了“huis”(意思是房子)。
  4. When refreshing the page everything is as it should be again刷新页面时一切都恢复正常

Is there a way to reset the translation once you translate back without having to reload the page?翻译回来后有没有办法重置翻译而无需重新加载页面?

Thank you!谢谢!

A cookie is set when translation is triggered.触发翻译时会设置 cookie。 The cookie (googtrans) Can be unset by letting it expire on a past date. cookie (googtrans) 可以通过让它在过去的某个日期过期来取消设置。 But even than you still need to reload the page to see it, probably the api does something like this already.但即使您仍然需要重新加载页面才能看到它,api 可能已经做了类似的事情。 So I thought of a solution where you reload the page with javascript when the native language is selected.所以我想到了一个解决方案,在选择本地语言时使用 javascript 重新加载页面。

It can be done by adding this piece of jQuery可以通过添加这块jQuery来完成

jQuery(document).on("change","#google_language_translator select",function() {
    if(jQuery(this).val() == 'nl'){ //value needs to be equal to default language, in my case nl
        location.reload(); 
    }
});

It feels a bit hacky so please let me know if there is something more clean感觉有点hacky所以如果有更干净的东西请告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM