Last year, one of the little apps that I put together was Translation Telephone, which lets you enter a phrase and translates it across 20 languages until finally translating back to the original language. It's interesting to see how some phrases transform - and sometimes the results sound almost like the output of an intelligent being. For example, "Capitalism: God's way of determining who is smart and who is poor." transformed into "Capitalism: God's way of determining who is smart and who is poor."
Unfortunately, not long after I made the app, Google announced it was shutting down the Google Translate API. There was a pretty big outcry after this announcement, and Google eventually decided to replace the free API with a paid translate API. Well, it's taken a while, but I've finally ported my app over to the paid translate API. I thought about replacing it with a non-Google free translate API, but I didn't find many good options, and the Google Translate API pricing is transaction-based and inexpensive: $20 per million characters of text.
To port over to the paid Google translate API, I did a few things:
- I registered an API key for my app using the Google APIs Console.
- I enabled the Translate API and billing in that console.
- I wrote a wrapper library that calls the Translate API v2 REST service via JSONP and transforms the result so it looks like Translate API v1. I then swapped the script tag that loaded in the Google JS APIs with one for that wrapper library instead.
You can see all the code changes in this commit. Once I made the v1-compatible wrapper friendly, I didn't have to change much of my original code. And maybe it will help other folks to port more easily.
Lesson learned: I've been putting off this port for half a year now, and it only actually took 20 minutes. I should have just spent an afternoon trying to port earlier instead of telling myself it would take a long time. One never knows with ports!
No comments:
Post a Comment