So, the day before yesterday, the Corporation of Good
has closed its free Translate API. The author until the last moment hoped that they would come
to their senses and not be
like the rest of them . Therefore, not scratched and did nothing. But then thunder struck. And in the CMS of one small 3-language project, the translator fell off. Not scary, but unpleasant - before, the admin on the content editing form 1 clicked on all the fields into 2 more languages. I wrote the translator by my grace, spent about 20 minutes on it and did not take a penny for it. Nevertheless, the client calls, threatens with physical violence over the beloved hamster, asks, again threatens. I had to close the bash and look for alternatives.
Under the cut list (4 options, no revelations / discoveries) that the author found, as well as the Javascript translation recipe from Bing.
Option 1, paid
It seems like the easiest and fastest solution is to take the Translate API v2 from the same Dobrokorporatsiya. But what is confusing - there is no simple JS example. Again - a security issue - I’ll need to add an API key to js. Those. Anyone who has guessed to open the source code of the page will be able to find the key there. And translate on my site at the expense of my client. Not too interesting. (I repent, I didn’t understand, maybe everything is provided there. But let me remind you the original message - Saturday evening, laziness, I want to go read the tower | beer | neighbor)
')
Option 2, criminal hemorrhoids
As suggested
here , for some reason, translation works. And even gives answers in JSON format. And Google itself proposes to use Translate Widget, which you can certainly dissect and see where it sends requests and how to emulate it.
This is where the questions arise - how long does it take to process these options? Is there any certainty that tomorrow (in a week) the shop will not be covered? Will you be able to get JSONP from them or will you have to bypass Same Origin Policy once again?
Are there many questions?
Option 3, the mythical
I remembered the love of a Russian search engine to copy the services of the Corporation D. He tried to google Yandex Translate API. Found only a mention of the existence of such a service and the fact that it is poorly documented. Probably it is not documented in any way, because at the moment the translator turns off from D., Inc. The whole RuNet would have to be full of links to this service, examples of use and excerpt from the documentation. Well, I’ll never believe that I’m the only one who didn’t give in to it in time, for sure there are still victims.
This is only an assumption, so do not kick much, if you have the information - welcome, in the comments links will only become accustomed.
Option 4th, treacherous
In the process of searching API from Yandex was incredibly surprised!
http://msdn.microsoft.com/en-us/library/dd877846.aspx We are given freebies! working! translator with JSONP support! And who is so generous? Microsoft! Looking ahead to say that the translator really works. The truth is to go from Google to Microsoft - is it somehow ... Is it unnatural or something? But nonetheless…
I gave a link to the example of use. An example, to put it mildly, cumbersome, but slightly documented. Yes, by the way, after a quick glance at the code, it is clear that some API key is required. But it's easy enough to get it - go
here , register and add the site. The interface podglyuchivaet slightly, but in general, the site turned out.
Yes, by the way, the translator with the same key worked for me on another (local) domain, in contrast, for example, from Dobrokart. The code was quickly reworked, using jQuery, it turned out a bit shorter and more readable. If you do not like jQuery, then either you yourself can solve a similar problem better and faster, or you still have to connect it in order for this function to work.
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' : 'YOUR_API_KEY', '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 }); }
I didn’t add comments to the code, I’m not obessudbte. Yes, and the function is documented for sure with any violations of something there. But, in my opinion, something can be understood. And most importantly - it works! (If you are not working - you are welcome to comment, preferably with an indication of the browser)
Yes, and also - the quality of translation compared to Google - sucks. At least the direction of RU -> UA.
If anyone has anything better, welcome to the comments.
And at the end of a little
pink snot of regrets - it seems like it's time to stop loving Google. I understand that the guys have to start making money, so they can no longer be kind and fluffy. It's a pity. Was it somehow ... magical or something? Want the map - on. Want a translator - on. How much do I owe? - Well, thank you for using our service. Damn, just some kind of tale. Is over.
Everything, I left to drink beer to the neigbour.
UPD: oh yes, we use JSONP, i.e. We will only send GET and naturally when translating more or less long text (I didn’t understand, but with 520 Cyrillic characters true) we would say HTTP 414 (which for some reason is called 404 in this particular case)