Thursday, December 8, 2011

Caching Google Translate

We've been using the free Google Translate for a while with the jquery-translate plugin (Copyright (c) 2009 Balazs Endresz (balazs.endresz@gmail.com))

Google decided this month to close the free version of their API and open version 2 for paying customers, in a model where they charge by characters count and capping the daily usage and the requests per second.

For this reason, we needed to purchase an account and use the new paid API.
Couple of major problems popped:
* The application for translating is based on client side code and the API key will be visible to everyone.

* The amount of daily translations (in characters) is by the millions.

We needed a quick solution for this problem.
The solution for the first problem (visible API key) was solved by creating a proxy server which have the API key and communicating the requests between the client side application to Google API.

To solve the other problem and reduce the amount of calls to Google API, we've implemented caching. We've taken every chunk of data which were needed to be translated and cached it. The problem was the unique cache key, which was resolved by using md5 hashing on the chunk of data that was sent to the proxy server with concatenation of the language. i.e. [SOME_HASH]_[LANGUAGE]
Related Posts Plugin for WordPress, Blogger...