Skip to content

Instantly share code, notes, and snippets.

@maruware
Created August 28, 2015 04:04
Show Gist options
  • Save maruware/a8edb2cb7e66848ff9c8 to your computer and use it in GitHub Desktop.
Save maruware/a8edb2cb7e66848ff9c8 to your computer and use it in GitHub Desktop.
og locales
<?php
$locale_tags = [
'en_US'=>[
'title'=>'hello',
'description'=>'hello world'
],
'fr_FR'=>[
'title'=>'Bonjour',
'description'=>'Bonjour tout le monde'
],
'ja_JP'=>[
'title'=>'こんにちは',
'description'=>'こんにちは世界'
]
];
$curr_locale = 'en_US';//default
if( isset($_REQUEST['locale']) ){
$curr_locale = $_REQUEST['locale'];
}
if( !isset($locale_tags[$curr_locale]) ){
throw new Exception('Bad locale');
}
?>
<html>
<head>
<meta property="og:locale" content="<?=$curr_locale?>" />
<?php foreach($locale_tags as $locale=>$tags): ?>
<?php if( $locale === $curr_locale ) continue; ?>
<meta property="og:locale:alternate" content="<?=$locale?>" />
<?php endforeach; ?>
<meta property="og:title" content="<?=$locale_tags[$curr_locale]['title']?>" />
<meta property="og:description" content="<?=$locale_tags[$curr_locale]['description']?>" />
</head>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment