Created
January 23, 2012 15:48
-
-
Save razbakov/1663905 to your computer and use it in GitHub Desktop.
Bing Translator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> | |
| <script> | |
| function translate_bing(text, sl, tl, success, complete){ | |
| if(typeof(complete) != 'function') | |
| complete = function(){}; | |
| jQuery.ajax({ | |
| url: 'http://api.bing.net/json.aspx?JsonCallback=?', | |
| dataType: 'jsonp', | |
| data: { | |
| 'AppId' : 'F3A5B8832ED2798D80A77717B631E18229AD3A84', | |
| 'Query': text.substr(0, 5000), | |
| 'Sources': 'Translation', | |
| 'Version': '2.2', | |
| 'Translation.SourceLanguage': sl, | |
| 'Translation.TargetLanguage': tl, | |
| 'JsonType':'callback' | |
| }, | |
| success: function(response){ | |
| success(response.SearchResponse.Translation.Results[0].TranslatedTerm || ''); | |
| }, | |
| complete: complete | |
| }); | |
| } | |
| $(function(){ | |
| $('#do').click(function(){ | |
| translate_bing($('#source').val(), 'ru', 'en', function(dat){$('#target').val(dat)}); | |
| }) | |
| }) | |
| </script> | |
| <body> | |
| Source: <input id="source"><br> | |
| <button id="do">Перевести</button><br> | |
| Translate: <input id="target"> | |
| </body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment