Thursday, February 3, 2011

How to localize Facebook pages

Well, you can't, but there is a workaround!
I spent a lot of time trying to display a Facebook page using the user language, that is to localize page content. All this just to come always to the same conclusion: this is not possible right now.
It's easy to display content based on user country, but often this is not enough. In Canada we have two official languages, English and French; other countries have two or more languages also.
So what is the solution? It's not so hard: create a Facebook application (google for "How to create a Facebook application" - you'll need to host your application somewhere though).
Facebook sends your app information about the user, passed to your URL using a POST request within a single signed_request parameter. When a user accesses the application, the signed_request parameter has a JSON array containing the locale and country of the current user.
In order to gain access to all the user information available to the application, the user must authorize the application, but for what we are trying to achieve this is not necessary.
All we wanted was the user locale, which allows localized content to be displayed.