Dirty hack while people who know about XOOPS and php are coming up with a good solution. I know nothing about php, servers, or anything else, and my little hack may be absolutely problematic, in which case I would be grateful if someone could tell me. But it seems to be working fairly well, for all the places where dates turn up on my site and are spit out by this particular function. Talking about News module, Article module, CBB3+. The following works for me on XOOPS 2.2.4 and PHP 5+
The task: Getting day and month strings to display in languages other than English.
The problem: As far as I could see, dates in XOOPS are often formatted by formatTimestamp function in local.php inside /xoopsroot/language/, which spits them out with php "date" function, which seems to be a little parochial when it comes to producing output in all this worlds nice languages. At least at php.net, it says one should use setlocale and strftime instead to get localized output. So that's what my dirty little hack is about.
In my language/yourlanguage/local.php, at the bottom of the function formatTimestamp, there's a line:
return ucfirst(date($datestring, $usertimestamp));
I've replaced that line with:
if ($datestring == "r"){
return ucfirst(date($datestring, $usertimestamp));
}else{
setlocale(LC_TIME, 'es_ES');
return ucfirst(strftime($datestring, $usertimestamp));
}
The "if" thingy to give the rss feed the output it needs, and all the other parts of the site should get the localized output. The es_ES thing has, of course, to be adapted to the specific language and server set-up, this one's for Spanish at my webhost.
Now, "strftime" takes a different input for $datestring then "date", and that part I've also hardcoded into local.php, instead of changing the language parameters in global.php. To not mess up any other function which might use them. In other words, inside the same function formatTimestamp, wherever it says something like _DATESTRING, I've replaced that with the format I wanted. In case l, for instance:
case 'l':
$datestring = "%d-%b-%Y, %H:%M:%S";
break;
That gives me something like: 10-ago-2006, 16:08:30. 'ago' being Spanish short for agosto/August. Reference here:
http://www.php.net/manual/en/function.strftime.phpCase 'mysql' is probably quite sensitive, for database input. I've figured I get the same output with:
case 'mysql':
$datestring = "%Y-%m-%d %H:%M:%S";
break;
I hope I'm not mistaken, but so far, I can still post to my forums and see a decent UNIX timestamp for it in the database. Finally, I went into the preferences of the News module and also changed the date string there to something with the percent sign.
Well, I know this is pretty dirty and needs to be manually adapted to the needs of a given server. Just thought I would share my hack, and I'd be very grateful if someone told me if this idea of mine is going to bring me into a deep mess down the line.