A few days ago, I published an article titled using Google Translate API to implement the multilingual translation function of the website. But some people tell me that Google is about to close some APIs, including Google Translate APIs. The following is the original article:
Recently, Google announced that it would shut down a number of Apis called Spring cleanup, including the Translate API (which was completely closed in December 1). Countless developers are using it to create a wide range of third-party translation applications. Google's explanation for this is that these Apis bring huge economic burden to Google and there are a lot of abuse behaviors.
Based on this situation, I started to look for other implementation methods, and found Baidu, sogou, Jinshan, and youdao. I found that none of the domestic translation services have a molding and external interface. In addition, I think of Bing. After looking for it, I had a developer tool. I didn't have to say anything. I went to the Demo.
Chinese-English-Chinese
The new movie "Mother's Day" by DALYs Bosman, Director 2, 3, and 4 has been downloaded. This film is a remake of the movie "Mother's Day" in 1980. dimoi, female xingrejia, played by "pushing the cradle hand", joins hands with "3D bloody Valentine's Day", "Dancing all-open", Brina aweigen, and "blood and true love "). shawn Ashmore)... New Generation handsome guy idol performances.
The implementation code is as follows:
Function translate () {// Chinese-English window. mycallback = function (response) {$ ("p" response .html (response);} var s = document. createElement ("script"); s. src = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate? Oncomplete = mycallback & appId = A4D660A48A6A97CCA791C34935E4C02BBB1BEC1C & from = zh-cn & to = en & text = "+ $ (" p ").html (); document. getElementsByTagName ("head") [0]. appendChild (s);} function translate2 () {// English-Chinese window. mycallback = function (response) {$ ("p" response .html (response);} var s = document. createElement ("script"); s. src = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate? Oncomplete = mycallback & appId = A4D660A48A6A97CCA791C34935E4C02BBB1BEC1C & from = en & to = zh-cn & text = "+ $ (" p ").html (); document. getElementsByTagName ("head") [0]. appendChild (s );}
For more interface documentation, see Microsoft Translator V2 API. Note that the first step of using Bing API is to apply for an AppId from Bing Developer Center, each application should use a separate AppId. Log in with the Live ID on the page, select Get a new App ID, and enter some basic information. Then you will Get a long string of AppId.
Finally, we provide a dummies web page translation tool, similar to the TranslateThis Button, which is a Web page online translation tool provided by Microsoft. You should also see the idea, this is easy to use. After setting the application page, you can insert a piece of JS into the page. Apply for the address: Click to enter, and finally generate a piece of code similar to this:
<script id="MicrosoftTranslatorWidgetScript" type="text/javascript">/* <![CDATA[ */ setTimeout(function() { var s = document.createElement("script"); s.type = "text/javascript"; s.charset = "UTF-8"; s.src = ((location && location.href && location.href.indexOf('https') == 0) ? "https://ssl.microsofttranslator.com" : "http://www.microsofttranslator.com" ) + "/ajax/v2/widget.aspx?siteData=NROHoI3oaj_KoRVH7WtBuQJ64x2eNXJK4KbfQk6f-zQ5PlXDd_9Z6FeiraMNlV7ONnQS8SlprkBxk6zOiVLuG9LGCd6pOSs3wFDI56ebaJSEJqeIz5GZl5G1e7o5zMig&mode=notify&from=zh-cn&layout=ts&toolbar=overlay&showLanguages=hi"; var p = document.getElementsByTagName('head')[0] || document.documentElement; p.insertBefore(s, p.firstChild); }, 0); /* ]]> */</script>
Appendix 1:
Tests show that bing translation has a small problem and will translate the content in the tag. For example, the content I want to translate is:
<A href = "http://tieba.baidu.com/ "> </a>
Google Translate:
<A href = "http://tieba.baidu.com/ "> saw </a>
The translation result of bing is:
<a href="http://tieba.baidu.com/chainsaw fright">chainsaw fright</a>
Bing not only translated the content in tag a, but also the translation was not so accurate. It seems that bing still has a long way to go in the translation process, I hope he can perfectly replace google translate.