views:

26

answers:

2

Hello everyone

I'm using constants to display my page titles in different languages:

 // lang.en.php
 define(_PAGE_TITLE, "Pagetitle");

 // lang.de.php
 define(_PAGE_TITLE, "Seitentitel");

I've placed a facebook like button on that page and everything works except for one thing: If I submit the link using the like button, the title in facebook shows up like this:

XY likes _PAGE_TITLE

The constant isn't replaced by it's value in facebook but it is replaced in the HTML code. Does anyone have an idea, why the constant isn't replaced if facebook grabs the pagetitle from my site?

Thank you.

Edit: Just found out, that the facebook bot has the HTTP_ACCEPT_LANGUAGE header set to english and there was a problem with my language file. Anyway, I would like the bot to take the german translation by default. Is there a way to catch the facebook bot and overwrite the language settings for it?

A: 

Facebook's server fetches your page and extracts the title to produce this information. So it's reasonable to guess that your system is (for some reason) rendering the page with a title of "_PAGE_TITLE" instead of the proper value from the language file. This implies that there is something special about facebook's automated request that is causing the language file to never get included.

So what causes the proper lang file to be included? What will your code do if it can't determine which language file to include (e.g. the 'Accept-Language` header is missing... or whatever).

It should fall back to including a default language file (probably english). There must never be a possibility to execute the script without having first included some language file.

Lee
I check it like this: $lang = (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) == "de") ? "de" : "en"; So it should fall back to english by default.
you should confirm that it is. try hitting your site with [curl](http://curl.haxx.se/) (there's a [php version](http://php.net/manual/en/book.curl.php) too). Or use a development proxy like [Charles Proxy](http://www.charlesproxy.com/) to simulate an incoming request like may be coming in from facebook. You might also have luck with examining your webserver logs to find requests from facebook's server, and see what's special about those requests. The point is-- something that's special about facebook's automated requests is causing your language file to not be included.
Lee
A: 

Asnwering to your edit, if you are using the new Facebook API or the Social Plugins, you can override the page title using <meta> tags like this:

<meta property="og:title" content="<?php echo _GERMAN_PAGE_TITLE; ?>" />

Remember! To use this meta property tags, you must declare the Facebook and Open Graph namespaces on the <html> tag.

<html 
    xmlns:og="http://opengraphprotocol.org/schema/"
    xmlns:fb="http://www.facebook.com/2008/fbml"
>

To further reading, take a look at this: http://developers.facebook.com/docs/opengraph

Coquevas