Search code examples
phpfacebookinternationalizationcakephp-2.0locale

Let facebook choose the right language with my share link


I have a multi-languages website (en_US + fr_FR), I made it using CakePHP.

The first time a user comes to my website, the language will be define using the $_SERVER['HTTP_ACCEPT_LANGUAGE'], or the default language (en_US) if $_SERVER['HTTP_ACCEPT_LANGUAGE'] is not set.

So the problem is that my OpenGraph tags are differents depending on the language, but the Facebook scraper doesn't have any $_SERVER['HTTP_ACCEPT_LANGUAGE'] var... so he'll always choose the default language (en_US), even if the user that clicked on the Share Link was French.

So my question is : How can I force Facebook to choose a different language when scraping my webpage.

I already took a look at this url : https://developers.facebook.com/docs/opengraph/guides/internationalization/ but I didn't understand anything...

Please, help !

(actually I'll have to do the same thing with Google+ share link too... but Facebook is more important right now)

EDIT : My webpage URL doesn't change when the language changes. It's always http://my-website.com/

EDIT 2 : I think I managed to make it works.

The answer was really in the doc : https://developers.facebook.com/docs/opengraph/guides/internationalization/ but it was really hard to understand.

But now how can I change my language in Facebook to check that it really works (because now, it always gives me the French translation instead of the default language) ?


Solution

  • Actually, I had to add a way to set the website language using the URL :

    http://my-website.com/en/ or http://my-website.com/?lang=en

    It is much more easier this way to share my website in different languages AND this is a recommandation from Google