2017-03-15 64 views
0

我在我的网站上有两个图片,可以说英文和韩文。当用户点击韩国国旗并返回英国时,我希望我的网页翻译成韩语。指定特定语言在图片上翻译网站点击

我想要一个JavaScript函数用于每个图像的onclick事件,然后调用Google Translate API或Microsoft Translate API并返回翻译后的页面。

我不知道这是否可能,但如果是这样,我会非常感激。虽然直接添加插件,但此时不适用于我。

谢谢...

+0

到目前为止您做了什么? – mehulmpt

+0

我已经把bing翻译小部件放在页面上,但这不是真正的喜欢... – Josh

回答

0

挖硬后......我拿出来与冰的解决方案翻译...

您可以发表评论的提醒等等。还有60000这里指如果在60秒内没有完成翻译,则会显示错误...

<!-- The image showing korean --> 
<img id="Koebtn" src="images/SP2.jpg"> 


<!-- The Code to translate --> 
<script src="http://www.microsoftTranslator.com/ajax/v3/WidgetV3.ashx?siteData=ueOIGRSKkd965FeEGM5JtQ**" type="text/javascript"></script> 
    <script type="text/javascript"> 
    $(document).ready(function() { 
     $("#Koebtn").click(function(){ 

     if (document.readyState == 'complete') { 
       Microsoft.Translator.Widget.Translate('en', 'es', onProgress, onError, onComplete, onRestoreOriginal, 60000); 
      } 

      //You can use Microsoft.Translator.Widget.GetLanguagesForTranslate to map the language code with the language name 
     function onProgress(value) { 
      document.getElementById('counter').innerHTML = Math.round(value); 
     } 

     function onError(error) { 
      alert("Translation Error: " + error); 
     } 

     function onComplete() { 
      document.getElementById('counter').style.color = 'green'; 
     } 
     //fires when the user clicks on the exit box of the floating widget 
     function onRestoreOriginal() { 
      alert("The page was reverted to the original language. This message is not part of the widget."); 
     } 

     }); 
    }); 
</script> 
+0

我会喜欢类似的解决方案,但用谷歌翻译API ......任何人的解决方案? – Josh