From 7eb21c5a5fab11e060d81f104404d3817ebe09c9 Mon Sep 17 00:00:00 2001 From: filip Date: Tue, 24 Feb 2015 19:23:42 +0100 Subject: news_date localisable on community page --- lib/news.php | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/lib/news.php b/lib/news.php index 397c18b52..7f8f09a4d 100644 --- a/lib/news.php +++ b/lib/news.php @@ -26,32 +26,17 @@ function html_news($locale = 'en', $count = 5) } /** - * @param string $dt + * @param string $dt date in the form ISO 8601 (2015-02-24T15:42:00+01:00) * @param string $locale * - * @return string + * @return string localised date */ function news_date($dt, $locale = 'en') { - $months = array( - 'en' => array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), - 'fr' => array('jan', 'fév', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'sept', 'oct', 'nov', 'déc'), - 'de' => array('Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez') - ); - $formats = array( - 'en' => 'M d Y', - 'fr' => 'd M Y', - 'de' => 'd. M Y', - 'default' => 'Y-m-d' - ); - $ft = array_key_exists($locale, $formats) ? $locale : 'default'; - - $dts = strtotime($dt); - $dt = date($formats[$ft], $dts); - if (array_key_exists($locale, $months)) - $dt = str_replace($months['en'], $months[$locale], $dt); - - return $dt; + $eng_months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); + $localised_months = array(_r('Jan'), _r('Feb'), _r('Mar'), _r('Apr'), _r('May'), _r('Jun'), _r('Jul'), _r('Aug'), _r('Sep'), _r('Oct'), _r('Nov'), _r('Dec')); + + return str_replace($eng_months, $localised_months, date(_r('M d Y'), strtotime($dt))); } /** -- cgit v1.2.1