php - How to translate this date format -


in template (drupal) php.tpl file have following:

               <?php                    print date('f j, y', $comment->created);                print ' @ ' . date('h:ia', $comment->created);                 ?> 

but doesn't print translation when site in foreign language. how make translate? using t() function? if so, how rewrite include it?

any , appreciated. :)

update:

isemi's 2nd solution below works fine except year prints y instead of year. minor adjustment code becomes:

$datef = t(date('f', $comment->created)); $datej = t(date('j', $comment->created)); $datey = t(date('y', $comment->created)); print "{$datej} {$datef} {$datey}" . t(' @ ') . date('h:i', $comment->created); 

the "at" easy translate becomes separate translatable string. notice space before "a" , after "t."

the date() function uses, believe, server's locale. ought change in current process, may awkward , not work in configurations.

you ought retrieve desired locale string, then:

setlocale(lc_time, 'it_it'); // depends on client.  $datel = strftime("%f %j, %y @ %h:%i:%s", $comment->created); 

but apart correct codes (i'm not sure %f , %j), still have problem of translating 'at', think.

alternatively can date piecewise , translate parts:

$datef = t(date('f', $comment->created)); $datej = t(date('j', $comment->created)); $datey = date('y', $comment->created); // numeric year not translated.  print "{$datef} {$datej}, {$datey} " . t('at')       . date('h:i', $comment->created); 

you use intl extension, see this answer.


Comments