Reputation: 565
On admin/config/regional/date-time/formats
I can set up date formats, like M jS
, and map them to date types on admin/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 be 12 Abr
. I need to translate also the format itself, so instead of M jS
, the Spanish version of the website will use j M
.
How can I achieve this? I tried searching on admin/config/regional/translate/translate
for these date formats. The Apr
->Abr
part is covered there, but not the format itself. I can't find strings like M jS
and so.
Upvotes: 4
Views: 10401
Reputation: 415
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>");
?>
Upvotes: 2