13

My website is multi-language and I have a FB like button. I'd like to have the like posts in different languages.

According to Facebook documentation, if I use the meta tag og:locale and og:locale:alternate, the scraper would get my site info passing the parameter "locale" and the header "X-Facebook-Locale", but it's not sending neither.(https://developers.facebook.com/docs/beta/opengraph/internationalization/). So the posts end always in en_US.

Anyone having the same problem?

om-nom-nom
  • 60,231
  • 11
  • 174
  • 223
Alouw Net
  • 131
  • 1
  • 3

5 Answers5

18

I got this working. The documentation is not very detailed; here are details.

Here are my Open Graph locale tags:

<meta property="og:locale" content="en_US" />
<meta property="og:locale:alternate" content="en_US" />
<meta property="og:locale:alternate" content="fr_CA" />

VERY IMPORTANT: The documentation makes it seem that og:locale should always reflect the page's "default" locale. This is not the case; doing so will prevent the scraper from retrieving other languages. og_locale must reflect the page's current locale. In other words, if the scraper (or the user) requests fr_CA content, make sure og_locale is set to fr_CA in the response.

Specify all possible locales with og:locale:alternate. This way, whether the scraper asked for en_US or fr_CA, it still knows that both exist.

Here's me asking the Facebook scraper to re-process my page:

curl -d "id=https://apps.facebook.com/everydaybarilla/&scrape=true" https://graph.facebook.com

Here's the response:

{
   "url": "http://apps.facebook.com/everydaybarilla/",
   "type": "website",
   "title": "Barilla\u2019s Every Day, Every Way Contest",
   "locale": {
      "locale": "en_us",
      "alternate": [
         "fr_ca"
      ]
   },
   "image": [
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/5.png"
      },
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/4.png"
      },
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/3.png"
      },
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/en-2.png"
      },
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/en-1.png"
      }
   ],
   "description": "Barilla Canada is whisking one lucky winner and a guest off to Italy on an 8-day Italian culinary adventure for 2 in the Barilla Every Day, Every Way Contest!",
   "site_name": "Barilla\u2019s Every Day, Every Way Contest",
   "updated_time": "2012-04-16T17:59:38+0000",
   "id": "10150594698421968",
   "application": {
      "id": "317271281656427",
      "name": "Barilla\u2019s Every Day, Every Way Contest",
      "url": "http://www.facebook.com/apps/application.php?id=317271281656427"
   }
}

The scraper correctly returns the data for the default locale, but according to the documentation, it seems that the scraper should scrape alternate locales as well; this is not the case. Clearly from the response above it sees the alternate locales, but it does not process them.

So, here's me specifically asking the Facebook scraper to process my page en français:

curl -d "id=https://apps.facebook.com/everydaybarilla/&scrape=true&locale=fr_CA" https://graph.facebook.com

This time, I correctly see two requests to my server from the scraper. The second request has both the X-Facebook-Locale header and the fb_locale URL parameter correctly set to fr_CA. And the POST correctly returns the French response:

{
   "url": "http://apps.facebook.com/everydaybarilla/?fb_locale=fr_CA",
   "type": "website",
   "title": "Concours Tous les jours, de toutes les fa\u00e7ons de Barilla",
   "locale": {
      "locale": "fr_ca",
      "alternate": [
         "en_us",
         "fr_ca"
      ]
   },
   "image": [
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/5.png"
      },
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/4.png"
      },
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/3.png"
      },
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/fr-2.png"
      },
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/fr-1.png"
      }
   ],
   "description": "Un heureux gagnant et son invit\u00e9(e) partiront \u00e0 destination de l\u2019Italie pour une aventure culinaire de 8 jours pour 2 personnes (valeur au d\u00e9tail approximative de 15 000 $)!",
   "site_name": "Barilla\u2019s Every Day, Every Way Contest",
   "updated_time": "2012-04-16T18:11:27+0000",
   "id": "10150594698421968",
   "application": {
      "id": "317271281656427",
      "name": "Barilla\u2019s Every Day, Every Way Contest",
      "url": "http://www.facebook.com/apps/application.php?id=317271281656427"
   }
}

Success!

Of course, after all this effort, when I go to the French Facebook.com and post this URL, the status box is populated… with the English data. It seems Facebook's own interfaces aren't configured to request the correct locale.

So even with all this effort, nothing seems to have been accomplished (translations of my strings via the Facebook translation app aren't working either, so I guess I shouldn't be surprised).

Still, it does answer the question. Perhaps somebody else can determine why the Facebook.com interfaces don't seem to request the correct locale.

Aaron Adams
  • 1,534
  • 15
  • 22
  • 1
    I've had basically the same problems as you but never got Facebook to scrape in other locales then en_US. I met a developer from Facebook yesterday at Facebook Developer Garage in Stockholm. I explained the problem and his answer was: Everything you need to know is in the doc page. There is nothing magic you have to do. He tried adding multi language support for OG objects two months ago and succeeded. He's only advice was try again and report all bugs. They will respond to these bug reports fairly quickly but I don't have the time or energy to report the bugs :( – Martin Torhage May 24 '12 at 11:51
  • 2
    Updated the docs to make your important point a little clearer – James Pearce Feb 25 '13 at 02:16
  • 3
    Hi, I have the same problem as you. **after all this effort, when I go to the French Facebook.com and post this URL, the status box is populated… with the English data.** Did you find any hints to hack it? – user2686101 Oct 26 '14 at 10:08
  • Sorry, I seem to recall giving up at the time! Although in fairness Facebook has done a *ton* of work in the years since to be *much* better at internationalization – hopefully somebody else can help you. – Aaron Adams Oct 27 '14 at 00:14
  • How I can see the result in Facebook? How to fake my locale as meta config locale to see real result instead json response? I tried to switch language in broswer but it seem not work. – Trần Bảo Huy Mar 19 '18 at 10:13
3

Facebook's locale handling is completely inconsistent

After wrestling with open graph locales for weeks now, I managed to post content with changing texts based on user's locale. For the links though, I'm still unable to get the expected results.

Here are my observations:

og:locale in the debugger shows by default, my actual facebook locale. Clicking on the og:locale:alternate links changes object properties as well as the interface language. I think it's by design.

The 'Raw Open Graph Document Information' section, without fb_locale appended to the input URL, shows the default data. If the fb_locale is set and in mixed case, Raw Open Graph Document Information section is changed according to the parameter. The 'Object properties' section still shows data based on actual / selected locale. If fb_locale is in lowercase, it returns 'Error parsing input URL, no data was scraped.'

The same thing is true for the 'locale' parameter appended to the debugger's (not the input) URL. If it's in mixed case format, Object Properties section and the interface language is changed. However, it does nothing when I pass it in lowercase (returns default/current locales)

Surprisingly, the graph api is acting inversely:

  1. when I request a re-scrape with php sdk

    1. the content is updated only when locale is passed in lowercase, but(!) in this case, the response returned doesn't have locale:locale parameter, which is set if either X-Facebook locale header or fb_locale parameter were present.

      All data in the response is in default locale. However, the wall post is updated and text is displayed correctly according to my facebook locale settings.

    2. if the locales are passed in mixed case format - as defined is the documentation -, request returns 'unsupported post request' error. When using php CURL function instead of the Facebook php SDK's api call, en_GB is an exception, where the response contains fb_locale and localized (english) content as well, but, the object properties / wall posts aren't updated, neither for en_GB. For other languages, 'Unspported post request' is returned.

  2. When I use the object's id (the id found on the bottom of the debugger page - by querying the 'comments_fbid' field from 'link_stat' table) instead of the URL:

    1. with mixed case locales, the response contains correct text and fb_locale for all locales, but none of them are updated. og:updated_time is unchanged in the debugger, but it's updated on https://graph.facebook.com/[object ID]

    2. with lower case locales, the result is the same as described in 1.1.

  3. In graph queries, the behaviour is again the opposite of the above: When I try to query https://graph.facebook.com/[object ID]?locale=en_GB, with mixed-case locales, it returns the expected result, with lower-case locales, it returns the default version with no locale (only locale:alternate) tags set. :-o

Is it possible that the graph api endpoint and the debugger treats the locales differently, making it impossible to get the same reponse from both?

btw with lower case locales, I managed to have localized posts on the feed, where the text is displayed based on the uer's locale.

Now my problem is that all links are pointing to the same canonical URL without any locale-specific information, because - as Salvador said -doing so would create different objects. See my post here: how to get the locale of a facebook user clicking on a localised object's link?

Community
  • 1
  • 1
1

I had the same issues until finally getting it to work by setting all locale values in the meta tags (og:locale and og:locale:alternate) in lowercase.

Check this out: http://developers.facebook.com/bugs/309825175774568?browse=search_5033cc14f42016961266549

After doing that and re-scraping, going to Facebook and changing the language settings to a supported locale would correctly send the X-Facebook-Locale and fb_locale, and trigger the desired results for me.

Btw: Setting the user locale to one not listed in og:locale:alternate would not send the header/get parameter.

0

What language did you specify when loading the Javascript SDK? It's easy to overlook that one.'

The default one is en_US, see the js.src line

<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=127211380649475";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
DMCS
  • 31,463
  • 14
  • 68
  • 103
0

I have the same problem.

The Like button sends to Facebook only his own attribute data-href="www.example.com/yourpage", not og meta tags values. Afterwards Fb scrapes og meta tags into yourpage, and from these creates the Wall post.
So practically the post is always in yourpage default language.

One solution to have posts in userlanguage is:

  • Add ?lang=userlanguage to data-href url of Like button
  • Give yourpage ability to get userlanguage and display meta tags og:title and og:description in the appropriate translation (e.g. with php $_GET)

So Fb will scrape yourpage in userlanguage and will create a locale post.

Unfortunately Fb create a single object for every different url ?lang=userlanguage1, userlanguage2... and every object has his own fans list.
So every translation of yourpage will have his locale fans.
:-(


Similar question: Open Graph Localization

Community
  • 1
  • 1
Salvador
  • 738
  • 8
  • 20