Created
March 28, 2012 15:00
-
-
Save lpetrov/2226888 to your computer and use it in GitHub Desktop.
og:locale og:locale:alternate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$cacheBuster = "t26"; | |
$possibleLangValues = array( | |
@$_REQUEST[ 'lang' ], | |
@$_SERVER[ 'HTTP_X_FACEBOOK_LOCALE' ], | |
@$_REQUEST[ 'fb_locale' ], | |
@$_REQUEST[ 'fb_ref' ], | |
@$_REQUEST[ 'locale' ], | |
); | |
file_put_contents("dbg.". $cacheBuster."-".time().".txt", var_export(array($_REQUEST, $_SERVER, $possibleLangValues), true)); | |
$lang = "en"; | |
foreach ($possibleLangValues as $_lng) { | |
if (substr($_lng, 0, 2) == "fr") { //supports fr_CA, fr, fr_FR | |
$lang = "fr"; | |
} else if (substr($_lng, 0, 2) == "en") { //supports en, en_US | |
$lang = "en"; | |
} | |
} | |
//locale | |
if($lang == "en") { | |
$locale = "en_US"; | |
} else { | |
$locale ="fr_CA"; | |
} | |
$og = array( | |
"fr" => array( | |
"title" => "Hello World - FR", | |
"description" => "Hello World Desc - FR", | |
), | |
"en" => array( | |
"title" => "Hello World - EN", | |
"description" => "Hello World Desc - EN", | |
) | |
); | |
?> | |
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta property="og:type" content="website"> | |
<?php foreach ($og[ $lang ] as $k => $v) { ?> | |
<meta property="og:<?php echo $k; ?>" content="<?php echo $cacheBuster.": ".$v; ?>"> | |
<?php } ?> | |
<meta property="og:url" content="https://facebook.dev.provisionsofia.com/apps/fb-localized-like-test/?cb=<?php echo $cacheBuster; ?>"> | |
<meta property="og:locale:alternate" content="fr_CA"> | |
<meta property="og:locale:alternate" content="en_US"> | |
<meta property="og:locale" content="<?php echo $locale; ?>"> | |
<style> | |
.active { | |
font-weight: bold; | |
} | |
</style> | |
<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/<?php echo $locale; ?>/all.js#xfbml=1"; | |
fjs.parentNode.insertBefore(js, fjs); | |
}(document, 'script', 'facebook-jssdk'));</script> | |
</head> | |
<body> | |
<div id="fb-root"></div> | |
<div> | |
<a href="?" <?php if ($lang == "en") { | |
echo "class='active'"; | |
} ?>>English</a> | | |
<a href="?lang=fr" <?php if ($lang == "fr") { | |
echo "class='active'"; | |
} ?>>French</a> | |
</div> | |
<div class="fb-like" data-href="https://facebook.dev.provisionsofia.com/apps/fb-localized-like-test/?cb=<?php echo $cacheBuster; ?>" data-send="false" | |
data-layout="button_count" data-show-faces="false" data-ref="<?php echo $lang; ?>" data-width="120"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment