This is the community forum. For a developer response use the Client Area.
Follow us on Facebook, Twitter and YouTube!

Date format in comment
#1

The format of the dates is strangely different in the comment and the response:

In the comment: Sat 22 June, 2013 (I need it to be Zat 22 Juni, 2013)
In the respone: Gisteren 12:49 (Dutch as needed)

Where to look to solve this?

Thanks
John
Reply
#2

Hi,

I don't think it's because one is a comment and the other is a reply.

It's because whenever the comment is today or yesterday it says "Today" or "Yesterday", and when the comment is older than that it will say the full date. At the moment Commentics doesn't support the display of multilingual dates, mainly because the last time I looked it was difficult in PHP to get a list of locales for the server that the script is on. I believe the PHP developers are working on this. In the meantime, what I've been recommending to people is to display the date as something like "26/06/2013". If you want to display the date in your own language, the code you would need to change is in /comments/includes/functions/comments.php

PHP Code:
<?php 
//Date
if ($cmtx_settings->show_date) {
$cmtx_box .= "<div class='cmtx_date_text'>";
if (
date("Y-m-d", strtotime($dated)) == date("Y-m-d")) { //if comment's date is today
$cmtx_box .= CMTX_TODAY . " " . date($cmtx_settings->time_format, strtotime($dated));
} else if (
date("Y-m-d", strtotime($dated)) == date("Y-m-d", mktime(date("H"), date("i"), date("s"), date("m"), date("d")-1, date("Y")))) { //if comment's date is yesterday
$cmtx_box .= CMTX_YESTERDAY . " " . date($cmtx_settings->time_format, strtotime($dated));
} else {
$cmtx_box .= date($cmtx_settings->date_time_format, strtotime($dated));
}
$cmtx_box .= "</div>";
}

Have you completed the interview?
Reply
#3

Steven,
The use of 'today' and 'yesterday' are clear to me, not a problem, working great.
The language of the days and months however are the issue.
The cms where I have included Commentics in, displays dates in Dutch, so I thought
it should be possible to do the same in Commentics itself.


In comments.php the variable $dated is used:
echo $dated;
results in direct output as : 2013-06-25 12:45:06
In the Comment display it is (re)formated as : Tue 25 June, 2013

Using the strftime variable in the same page (with setlocale (LC_TIME, 'nl_NL'); )
echo strftime ("%A %e %B %Y", mktime (0, 0, 0, 6, 25, 2013));
results in output as : dinsdag 25 juni 2013 (that's what I need)

So the numeric base for the date is there in the $dated variable.
As far as my limited knowledge of php tells me, it should be possible
to format the date string into another (Dutch) language?
Reply
#4

Yes it's possible, but it's the "setlocale (LC_TIME, 'nl_NL');" part which is the problem.

In your case the locale 'nl_NL' works fine. However this may not work on another server. Another server might not have the Dutch locale installed, or it may be installed but called something other than 'nl_NL'.

For example, on the PHP doc page for the setlocale function, the example is trying to guess what the locale for German is because it can have so many different variants:

PHP Code:
<?php 
setlocale
(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');

Sure I could leave it up to the admin to try to determine what locales they have on their server and get them to type it in somewhere. But I'd prefer for there to be a user-friendly way. Ideally there would be a drop down menu in the Installer where you could select from a list of available locales. I know that some scripts do this so it must be possible, it's just I haven't had chance to look into it that much. I know you can get a list of locales with "system('locale -a')" but many servers have the system() function disabled.

Does your CMS have a way to choose which locale to use? How did you know that 'nl_NL' would work?

Have you completed the interview?
Reply
#5

(27-Jun-2013, 03:38 PM)Steven Wrote:  Does your CMS have a way to choose which locale to use? How did you know that 'nl_NL' would work?

The cms I use asks at install the language you want to use.
Though not always easy as far as 3rd party modules are concerned, overall the date format is flexible and completely Dutch.

The basic language config of the cms, where locale is also defined in a *.nls file. Such file is available for a great amount of different languages with each their specific locale :

Code:
#Dutch (Netherlands)

#Native language name
$nls['language']['nl_NL'] = 'Nederlands';
$nls['englishlang']['nl_NL'] = 'Dutch';

#Possible aliases for language
$nls['alias']['nl'] = 'nl_NL';
$nls['alias']['dutch'] = 'nl_NL';
$nls['alias']['nl_NL.ISO8859-1'] = 'nl_NL' ;

#Possible locale for language
$nls['locale']['nl_NL'] = 'nl_NL,nl_NL.utf8,nl_NL.UTF-8,nl_NL.utf.8,nl_NL@euro,dutch,Dutch_Netherlands.1252';

#Encoding of the language
$nls['encoding']['nl_NL'] = 'UTF-8';

#Location of the file(s)
$nls['file']['nl_NL'] = array(dirname(__FILE__).'/nl_NL/admin.inc.php');

Not sure if it matters but in my .htaccess file is also included :
Code:
SetEnv TZ Europe/Amsterdam
DefaultLanguage nl-NL
Reply


Possibly Related Threads…
Thread / Author Replies Views Last Post
Last Post by Mark
25-Mar-2023, 11:45 PM
Last Post by Steven
06-Nov-2020, 07:26 PM
Last Post by WhatSay
20-Aug-2020, 12:20 PM
Last Post by Steven
31-Dec-2014, 06:19 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)