Skip to content

Instantly share code, notes, and snippets.

@robinbastien
Last active May 23, 2017 17:37
Show Gist options
  • Save robinbastien/f5384dcbc77498b6d2fb to your computer and use it in GitHub Desktop.
Save robinbastien/f5384dcbc77498b6d2fb to your computer and use it in GitHub Desktop.
WPML - Multilingual Date Function
<?php
/*
* Friendly Date (WPML)
* Adds a date in the proper language based on a timestamp
* @param timestamp $timestamp A unix timestamp
* @param language $language The locale code. In most cases this will be ICL_LANGUAGE_CODE
* @param short $short The date format to output (eg: 'l F jS, Y')
*/
function friendly_date_wpml($timestamp, $language, $short) {
$format = ($short) ? 'F jS' : 'l F jS, Y';
$date = date($format, $timestamp );
// if french, show french date
if( $language == 'fr' ) {
setlocale(LC_TIME, "fr_FR");
$format = ($short) ? "%e %B" : "%A le %e %B, %Y";
$date = strftime($format, $timestamp);
$date = htmlentities($date, ENT_COMPAT, 'ISO-8859-1');
}
return $date;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment