Facebook like inline translation

facebook tranaslations

Facebook’s inline translation is an AJAX, Javascript and PHP combination powered by Bing translator.

How does Facebook inline translation work?

(Technical stuff follows…)

When you click “See Translation,” for a non-english texts, it sends a request to a php file, translate_comment.php, with parameters such as comment id, user id, and other unrecognizable ones like ft_ent_identifier and so on. The full link would look like,


You can watch what happens behind the scenes with HttpFox for Firefox and with developer tools (network tab) on Chrome. On HttpFox, you can switch to Raw mode on the POST data tab to get all the parameters together.

httpfox raw mode post data

Using just few of the main parameters alone, would work. The parameters are,

ft_ent_identifier, comment_ids[0], source, __user and __a.

You can omit the rest, like I have done in the link above.

translation  json output

Running that link will output results in a JSON data structure, a javascript code processes it and outputs the translated text, inline, in the place of “See Translation” along with the text link,  (Translated by Bing). The text that’s translated is russian and is, Саша, а мне нравится. facebook translation

You can change the comment ID on the translate link and get it translated as well.

 How to implement it on your website?

Google translate has become a paid one, at 1 million words for $20. While Microsoft has a free solution you can still use. As, Google translate has a widget for free usage, and the API is paid one, we’ll look at using Microsoft’s API which is available for free!

The code to translate any text of any language is,

You can try it out here below, which is an inline translate similar to the Facebook’s one. Just enter any text of any language to translate and hit translate button. The auto-detection of language is achieved by setting the translate from, variable to null like in the link in the code above.

It is also easy to try like Facebook’s one with the translated words replacing “See Translation” or anything similar. The code above doesn’t correct when a text is entered with spelling mistakes or incorrect. It doesn’t handle that.

For a Facebook like inline translation, here’s one below,

The code is modified a bit,

Leave a Reply

Your email address will not be published. Required fields are marked *