How to translate Date Formats on Drupal 7?
You can use the drupal 7 t() function: http://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/t/7
Anything that goes through the t() function has to be manually translated in the back-end Configuration > Regional and language > Translate interface. That means you'll have to manually put in the translations for the days and months.
Sample code:
<?php
global $language;
$day = t(date('l'));
$month = t(date('F'));
$dayNum = date('j');
$year = date('Y');
$output = t('@day, @month @dayNum, @year', array(
'@day' => $day,
'@month' => $month,
'@dayNum' => $dayNum,
'@year' => $year
));
print ("<p class='today'>".$output."</p>");
?>
Jorge Suárez de Lis
Updated on June 04, 2022Comments
-
Jorge Suárez de Lis almost 2 years
On
admin/config/regional/date-time/formats
I can set up date formats, likeM jS
, and map them to date types onadmin/config/regional/date-time
, like "Short format date".Now I want to set up a multilanguage website, so I not only have to translate the month or week names itself, but choose a different date format based on language. That is,
Apr 12th
is OK on English, but translating Apr to Abr won't make it much better on Spanish:Abr 12th
--should be12 Abr
. I need to translate also the format itself, so instead ofM jS
, the Spanish version of the website will usej M
.How can I achieve this? I tried searching on
admin/config/regional/translate/translate
for these date formats. TheApr
->Abr
part is covered there, but not the format itself. I can't find strings likeM jS
and so.