Localization
Open Graph supports internationalization (i18n) of actions and objects for use in multiple languages. Once an app’s text strings are in the Facebook system for translation, you can translate the strings or leverage the community or people using the app for translation. (People can help translate using theTranslations app.) Once translated, text strings must go through the same approval process as other translated strings. That is, the language administrators and owners must agree that the translations meet with Facebook guidelines.
Self-Hosted Objects
Self-Hosted Open Graph Objects are annotated web pages with a set of meta tags that provide property values. Object properties include the title, description and any custom properties. Objects are connected to people using apps via actions, and when this happens, an object appears in timeline, news feed and ticker.
Object property values can be stored in multiple languages. To make sure your object is scraped in multiple languages, make sure to do either of the following:
- Call the Graph API to update the object URL with the
locale
parameter. - Specify an array of
og:locale:alternate
meta tags to define which locales you support.
The Open Graph Object Crawler will include
fb_locale
parameter in the URL (for example, ?fb_locale=en_US
) and also in the X-Facebook-Locale header. If the app has localized text for that language, it should return the tags with strings matching the header. Facebook stores those strings hashed by the language.
To take advantage of this, start by adding the
og:locale
meta tag markup to your web pages. It is an optional property, and it will accept one of the Facebook specific locales. To ensure that an object supports a language you should either scrape it via the Graph API call (add the <code>locale</code>
parameter to the object scrape api or add the og:locale:alternate
meta tag). You can specify multiple og:locale:alternate
tags if you support different languages.<html>
<head>
<meta property="og:locale" content="en_US" />
<meta property="og:locale:alternate" content="fr_FR" />
<meta property="og:locale:alternate" content="es_ES" />
<meta property="og:title" content="Beef steak" />
...
Then, when your object is crawled by Facebook (see Using the Object API for details on publishing an object to Open Graph), we'll add a new HTTP header called
X-Facebook-Locale
and the fb_locale URL parameter. This should be considered a hint for what locale the app is looking for. By looking at this parameter, your app should return the Open Graph meta tags in the requested locale with theog:locale
meta tag now echoing what was requested. (If your app doesn't have data in this locale, you can return a "default" version where the og:locale
isn't specified, or data for another locale.)<html>
<head>
<meta property="og:locale" content="fr_FR" />
<meta property="og:locale:alternate" content="en_US" />
<meta property="og:locale:alternate" content="es_ES" />
<meta property="og:title" content="Bifteck" />
...
The
og:url
and og:type
for all localized objects are the same. Other meta tags for localized objects can be different.
Apps can also request a recrawl by passing the
locale
attribute to the Graph API’s scrape endpoint via HTTP POST. For example:
Crawl in English:
POST https://graph.facebook.com?id=http://example.com/movie/inception&scrape=true&locale=en_US
Crawl in French:
POST https://graph.facebook.com?id=http://example.com/movie/inception&scrape=true&locale=fr_FR
To scrape an object for more than one language, you can specify the languages comma-separated in the
locale
attribte. For example:
Crawl in English, French, Spanish, and Portuguese:
POST https://graph.facebook.com?id=http://example.com/movie/inception&scrape=true&locale=en_US,fr_FR,es_LA,pt_BR
When an object property changes, or when an app decides to add a new language to support, you should also make the Graph API call for each language supported to update the object definitions inside Facebook.
Hosted Objects
Hosted Objects are created via Facebook's Object API. They are hosted on Facebook's servers instead of being hosted on your server.
It's possible to add a localization to an object after it's been created. You create a localization for an object by posting a new object to the ID of the created object with a
locale
field in the object.
For example, if you created a custom object in Spanish:
curl -X POST \
-F 'object={"locale":"es_ES",
"title":"mi objeto",
"description":"mi descripción",
"data": { "obj_extra":"mi información" } }' \
"https://graph.facebook.com/$APPID/objects/testme_like_app:foo?access_token=$APPID|$APPSECRET"
It returns an ID:
{"id":"645752348782873"}
You can then use this ID to create an English version of the object:
curl -X POST \
-F 'object={"locale":"en_US",
"title":"my english object",
"description":"my english description"}' \
"https://graph.facebook.com/176240875865138?access_token=$APPID|$APPSECRET"
This will return the object you just created:
{
"type":"testme_like_app:foo",
"title":"my english object",
"locale":{"locale":"en_us"},
"description":"my english description",
"updated_time":"2013-08-12T23:20:57+0000",
"id":"645752348782873",
"application":{
"id":"384179895015798",
"name":"Test Like App",
"url":"http:\/\/www.facebook.com\/apps\/application.php?id=384179895015798"
}
}
Once you've created two locales you can request either version with the
locale
parameter. Here are the two versions of the object:
No comments:
Post a Comment