How to localize Facebook Javascript SDK dynamically with PHP

Here is a quick snippet on how to localize your Javascript SDK based on your user’s locale preference, there are localized Javascript SDKs in all of Facebook’s supported locales.

Once you get the user object with the PHP SDK, just use the ‘locale’ attribute to build your javascript source.

So instead of simply serving this to everyone.

//connect.facebook.net/en_US/all.js

Try serving this instead. (Assuming you loaded the user’s basic info into a variable called ‘user’.)

//connect.facebook.net/<?php echo user['locale']; ?>/all.js

Check out this page  on the Facebook documentation for more information on internationalizing Facebook applications.

Leave a Reply