Instead of using php's date, use drupal's format_date to avoid problems with non-english dates.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Se7enLC’s picture

Are there problems with non-english dates? I think php is i18n-aware - I've seen somebody using this application in a foreign language and the month names were changed to match.

The problem with using format_date() will be that it forces you to use the same date format as the rest of drupal, and the same date format in every block. In some cases it might be beneficial to use just the time, or just the month name in one block, and a full date in another. People seem to like customizations of things like this.

I could probably patch it such that the default date is the one selected in drupal admin, but still leave it overridable.

Joackim’s picture

The Drupal API states that format_date can be called with $type = 'custom' and the $format set to a PHP-date compatible string. It would simply be a matter och changing date($timestamp, $format) to format_date($timestamp, 'custom', $format). This should be fully compatible with the current code or am I missing something? The benefit of the change would be that it allows multiple languages on the same drupal site.

giuppe’s picture

Version: 6.x-1.4 » 6.x-1.x-dev
FileSize
15.21 KB

Hi,
the php date() function does not translate weekdays' and months' names, (e.g. date("F") will output "February" even when drupal is translated). As Joackim said, drupal format_date() can be used as a replacement for php date() using $type='custom'.

So I made a patch that changes the various date() to format_date(), keeping the per-block date format.
I added also various missing t() that I hope will aid the overall module i18n.

P.S.: keep up the good work with this great module! :)

giuppe’s picture

Status: Active » Needs review

I forgot to change the status of the issue.

nachenko’s picture

Actually, PHP DOES translate dates, as long as you "tell" the script the country and language you want the date for. Check "setlocale" function for details.

Metasequoia’s picture

How do I use the setlocale function exactly? I have no knowledge of PHP, but I want to display the weekdays and month names in a different language than english. I currently use the 7.x version of the module.

jdwfly’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

Will look at soon.

bohemier’s picture

Issue summary: View changes
FileSize
6.91 KB

Recreated the patch for 7.x-1.x-dev