How to implement internationalization of OG-Tags?

2019-02-02 15:50发布

问题:

for an upcoming project we wanna translate our app to multiple languages. Having a look at Facebook's How-To: Open Graph Internationalization page, you get very detailed information on doing this.

So, we implemented the tags correctly. When viewing the page as a english-speaking user, you get:

<meta property="og:url" content="https://site.url" />
<meta property="og:title" content="English title" />
<meta property="og:description" content="English description" />
<meta property="og:locale" content="en_US" />
<meta property="og:locale:alternate" content="de_DE" /> 

For german users, it looks like vice-versa:

<meta property="og:url" content="https://site.url" />
<meta property="og:title" content="German title" />
<meta property="og:description" content="German description" />
<meta property="og:locale" content="de_DE" />
<meta property="og:locale:alternate" content="en_US" /> 

As described in the documentation, we look at the "?fb_locale"-get parameter and in addition, parse the HTTP_X_FACEBOOK_LOCALE header to decide, which translation should be displayed.

So, my questions are as following:

  1. When debugging the mentioned url with Facebook Debugger (whatever language used in the debugger (with ?locale=de_DE e.g.)) english texts are displayed. Is this a bug of debugger or intended behavior?

  2. When clicking of the alternate locale link within debugger, a ?locale=de_DE is attached to the debugger-url and the interface is changing to german. but the locale isn't passed to the url itself, as it looks, because the scraped texts remain in english. Any hints on this one?

  3. When manually attaching the "?fb_locale=de_DE" parameter to the url in the debugger, the "object properties" section of the debugger remains english, whereas the "raw open graph document information" contains the german translations. Is this correct or should the "object properties" update as well?

  4. Is there any site out there using proper internationalization of og-tags that you know of? It would be awesome to see a fully-functional example in the wild.

  5. When pasting the mentioned site url directly in Facebook newsfeed (as an user with german Facebook), Facebook displays only the english og texts. Shouldn't it display the german texts in this scenario, when everything's implemented correctly?

回答1:

I had the same problem and wrote to facebook support. Their answer was like this:

... The use case for Open Graph Localization is not for sharing links on Facebook and having the meta data localized. Instead it is meant to be used as part of custom Open Graph stories such as "X completed a level".

Basically when an open graph story is published using a link to a self-hosted object, only then will we send the fb_locale parameter and X-Facebook-Locale HTTP header.

You can follow this link for details: https://developers.facebook.com/bugs/141601252889984



回答2:

I answered my own question: here

You have to refresh the cache of facebook.

curl -X POST -F "id=http://yoururl" -F "scrape=true" -F "locale=fr_fr" "https://graph.facebook.com" -s

(in my example, I used fr_fr)