Assuming a lot of people are just trying to translate dynamically a fan page tab on Facebook since the old tag restricted to (<fb:restricted-to>) is deprecated, I will just list step by step what you have to do. If you need more details, don’t hesitate to ask in the comments below. Everything is done here with PHP.
Examples
Just so you know what we are trying to do there, here is a list of Facebook pages using this functionnality:
Actually Coca-Cola seems to use another method than the one described here because changing the browser language or the Facebook language does not affect the fan page. I think they use IP geolocalisation.
Step 1 – Create your application
Create a new application on the Facebook developper app.
I will assume that you already have the Facebook developper application installed on your Facebook account, if I assume wrong try to go on the Facebook developper application and enable it. You will also have to confirm your account with your phone or by adding a credit card to your Facebook account.
Step 2 – Configure settings of you Facebook application
Since march 2011 Facebook does not allow anymore application to be hosted on his platform. You must now have a server to host you application.
Fill the form under the tab « Facebook integration » with the informations Facebook needs (leave the others empty):
- Canvas Page: it’s like a unique string for your application which will compose the URL to access to the canvas,
- Canvas URL: canvas is actually the « back-office » of your app and since we don’t really need it, just fill this field with a path to an almost empty index.html,
- Tab Name: the name of the tab which will be added to your fanpage,
- Tab URL: the path to the real content of the tab.
As you can see, you just need to have hosted 2 folders. Mine are here:
- the no canvas page: http://fwed.fr/devquotes/my-translated-app/,
- the tab page: http://fwed.fr/devquotes/my-translated-app/tab/ (the language detection is based on the Facebook language set by the visitor, so if you go directly to this URL you will see the default case which is in english).
Step 3 – Code the app
Now the app exists on Facebook, we have to make it real on your server (like the 2 URLs of mine).
The Facebook PHP SDK is needed to ensure our application to be translated in the language the visitor set on his Facebook (and not on his browser). You can get it on github: Facebook PHP SDK. All you need then is to include this SDK in your code (the code of the tab page, not the canvas) and initialize it this way:
$app_id = "your_app_id_here";
$app_secret = "you_app_secret_here";
require_once 'facebook.php';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
Your app ID and app secret can be found at the top of the screenshot from the step 2. Once this step is done, we want now to find the language aimed. Facebook, through its API, allow us to access few informations about the visitor:
$signed_request = $facebook->getSignedRequest(); //var_dump($signed_request); $locale = $signed_request['user']['locale']; $country = $signed_request['user']['country']; //var_dump($locale);
You can uncomment the var_dump to see what Facebook offers but so far we have in $locale what we need. Just a few more scripting and the automatic translation will be ready to work:
if(stristr($locale, 'fr')) {
// french content
}
else {
// english content
}
Step 4 – Add the application to your page
Now everything is set you have to go on the home of the developper application and click on « Application profile page ».
Once on the page of your application, click « Add to My Page » and chose the page you want the application to be displayed.
Go on your page and see the application working.
Hope this tut was useful. If informations are missing just ask for it in the comments, we are really reactive during the week :)






[...] How to create a Facebook page dynamically translated | devquotes, [...]
Hi there,
it’s a great tutorial! Thanks guys! But unfortunately I get an HTTP 500 Error… Any help maybe?
I am not sure weather it is correct to use « require_once ‘facebook.php’; » without an URL?
Is it maybe possible to see your completely original file?
Thanks in advance
Sascha
Hello Sascha,
The facebook.php file has to be hosted on your server too. Right next to your « tab page » file, somewhere it can be included.
Can you tell me at which moment you are getting the HTTP 500 error?
I will try to upload my source files when I have the time.
I am such a stupid guy! Now I understood an everything works! Thank you so much for your help and sharing your knowledge!
Cheers
Sascha
You’re welcome :)
Hope your 4500 fans will like it :P
How cool! You found me on facebook! ;)
Thanks man! Just tell me, if I can help YOU. Maybe you wanna do a prize draw for your users? Just let me know, I can send you a hotel voucher as a service in return.
I am that happy about it, because I was looking since months for a solution of this topic ;)
And maybe I can snatch a back link for our site hotel.info ;) *kidding*
Cheers
Sascha
Hehe!
Actually a hotel voucher would be really much appreciated (and a backlink also :D), it’s really nice of you!
We are really happy to have brought you a solution for your Facebook problem, at my office we were stuck the same way, that’s why I decided to spread the solution when i found it :)
Can we maybe continue this conversation by email? We would love to visit berlin! :)))
fred
Hello. It didn’t work for me :( I clicked your test link it works but I tried but nothing happened. What should I do?
Hi Ali, can you explain what is the step where you are stuck?
He fwed. I added the codes to my index.php and codes gave me an error. I don’t know what’s wrong.
Please show me the error code using pastebin: http://pastebin.com/ :)
(and paste your code also)
Hi fwed. That’s my code:
http://pastebin.com/cwVHsqc9
I don’t have a specific error code. I get a blank page and codes didn’t work.
Ali,
Did you put the facebook.php file in the same folder?
You could try to write on the top of the code (it will displays errors if there are some):
ini_set(‘display_errors’, 1);
ini_set(‘log_errors’, 1);
ini_set(‘error_log’, dirname(__FILE__) . ‘/error_log.txt’);
error_reporting(E_ALL);
hi,
Is there a way to translate the tab name depending on the facebook user’s language?
Hi Andre,
Effectively it seems there is a way, by example AccorHotels is doing it here: http://www.facebook.com/accorhotels
(just change the language at the bottom of Facebook)
But so far I did not find how to do that.
fred
Thank you so much for this great tutorial. Its worth reading and sharing now to help new facebookers to create a facebook page.
Cheers.
Robin
Works like a charm! Thank you for dummy-friendly tutorial :-)
Hi!
I was curious… If the user has not yet authorized my application is it possible to figure out what country they are visiting the site from?
–d
Hi Luke,
Totally yes. The country they are from is one of the data we can access without authorization.
fred
great. thanks
Hi,
I click in the bottom select lang y the app doesn’t work… the text is always the same: not french… but my lang is FRENCH !
:(
any ideas?
$facebook = new Facebook(array(
‘appId’ => $app_id,
‘secret’ => $app_secret,
‘cookie’ => true
));
$signed_request = $facebook->getSignedRequest();
//var_dump($signed_request);
$locale = $signed_request['user']['locale'];
$country = $signed_request['user']['country'];
//var_dump($locale);
echo « my site is « ;
if(stristr($locale, « fr »)) {
echo « french »;
}
else {
echo « not french »;
}
?>
Hi Flamarti,
have you tried already ‘fr-FR’, I think sometimes Facebook needs information about the country…
Cheers
eloquium
Yes I’ve tried but doesn’t work.
I’ve activated the var_dump($signed_request); and the var_dump($locale); but the answer is still
NULL NULL my site is not french
The strange thing is that if I try to open my site url http://mysite/translate/index.php
the answer is the same… seems that fb doesn’t « calculate » anything…
I haven’t got any ideas..
:(