Topic: date vs strftime
Hello !
punbb use the fonction date() wich not allow the use of the locals to display the date in specific language. Is it because the use of strftime is lower ? If no, is it possible to use strftime in the next version ?
You are not logged in. Please login or register.
PunBB Forums → PunBB 1.2 discussion → date vs strftime
Hello !
punbb use the fonction date() wich not allow the use of the locals to display the date in specific language. Is it because the use of strftime is lower ? If no, is it possible to use strftime in the next version ?
You can make your own date translate function. It's not that hard. In function.php on 595 change
$date = date($pun_config['o_date_format'], $timestamp);
$today = date($pun_config['o_date_format'], $now+$diff);
$yesterday = date($pun_config['o_date_format'], $now+$diff-86400);
to
$date = ldate($pun_config['o_date_format'], $timestamp);
$today = ldate($pun_config['o_date_format'], $now+$diff);
$yesterday = ldate($pun_config['o_date_format'], $now+$diff-86400);
Then, add a new function to functions.php. This is for Dutch, but you can easily translate it.
function ldate($format, $timestamp = '')
{
// same as date() function, only change names to locals
if ($timestamp == '')
{
$timestamp = time();
}
$date = date($format,$timestamp);
// change names of the days
$date = str_replace('Monday','maandag',$date);
$date = str_replace('Tuesday','dinsdag',$date);
$date = str_replace('Wednesday','woensdag',$date);
$date = str_replace('Thursday','donderdag',$date);
$date = str_replace('Friday','vrijdag',$date);
$date = str_replace('Saturday','zaterdag',$date);
$date = str_replace('Sunday','zondag',$date);
// change names of the months
$date = str_replace('January','januari',$date);
$date = str_replace('February','februari',$date);
$date = str_replace('March','maart',$date);
$date = str_replace('April','april',$date);
$date = str_replace('May','mei',$date);
$date = str_replace('June','juni',$date);
$date = str_replace('July','juli',$date);
$date = str_replace('August','augustus',$date);
$date = str_replace('September','september',$date);
$date = str_replace('October','oktober',$date);
$date = str_replace('November','november',$date);
$date = str_replace('December','december',$date);
return $date;
}
Why re-invent the wheel ? srftime handle all this, without need to hack PunBB or maintain the code.
The "problem" with strftime is that it requires the proper locale to be loaded and it hardly ever is. Even worse, setting it through PHP (via setlocale()) also very seldomly works because hosting companies generally forget to install the different locales.
by default, if locals are not installed, strftime don't give any result (in english) ?
The default locale is C (posix) which means English (or so I think).
So what's the problem ?
In all case english is available, and for specific use (different language) the user is advertise that the good local has to be installed, if not the use is like the function date...
Am i wrong ?
The problem right now is upgrading. People will freak out when their customized date format is reset and the old one they used doesn't work anymore.
Localization vs people don't reading documentation *and* using bad hosting ? Is this a real question ? :-)
PunBB Forums → PunBB 1.2 discussion → date vs strftime
Powered by PunBB, supported by Informer Technologies, Inc.