1 (edited by 2010-10-09 11:12:16)

Topic: [HACK] Translate the date (show_news.php)

Name: Translate the date
Author: FUNimations, though other versions have been on the forum https://cutephp.com/forum/style_emoticons/default/wink.gif
CuteNews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Description: Translate the month/weeknames
Requirements: The date template hack
Instructions:
Be sure to have that other hack installed. It'll be easier to implement the hack
open functions.inc.php and add before (at the bottom of the file)

?>


function my_date( $data, $type )
{
$list = array();
$list['months'] = array();
$list['months']['1'] = "januari";
$list['months']['2'] = "februari";
$list['months']['3'] = "march";
$list['months']['4'] = "april";
$list['months']['5'] = "mai";
$list['months']['6'] = "june";
$list['months']['7'] = "juli";
$list['months']['8'] = "august";
$list['months']['9'] = "september";
$list['months']['10'] = "october";
$list['months']['11'] = "november";
$list['months']['11'] = "december";
$list['weekday'] = array();
$list['weekday']['1'] = "monday";
$list['weekday']['2'] = "tuesday";
$list['weekday']['3'] = "wednesday";
$list['weekday']['4'] = "thursday";
$list['weekday']['5'] = "friday";
$list['weekday']['6'] = "saterday";
$list['weekday']['0'] = "sunday";
return $list[$type][$data];
}


Now comes the trick to translating the dates. It's a bit tricky so keep your mind with it and UNDERSTAND what you're doing.
As mentioned in the 'Date Template Hack' depending on the tokens(parameters) entered the date() function will return a value. It's important in order to use this hack that the return value is a number without leading zeros
now let's translate the month

$output = str_replace("{month}", date("n", $news_arr[0]), $output);


will become

$output = str_replace("{month}", my_date( date("n", $news_arr[0]), 'months'), $output);


now the {month} will be replaced with the translated month name.

We don't have a tag for the 'weekday' so add this line

$output = str_replace("{weekday}", my_date( date("w", $news_arr[0]), 'weekday'), $output);

Posts: 2

Pages 1

You must login or register to post a reply

CutePHP Forums → Hacks & Tricks / FAQ → [HACK] Translate the date (show_news.php)



The pun_antispam official extension is installed. Copyright © 2003–2009 PunBB.