How to translate date formats to Drupal 7?

In admin/config/regional/date-time/formats I can configure date formats, for example M jS , and map them to date types on admin/config/regional/date-time , for example, "Short-term date".

Now I want to create a multilingual website, so I need to not only translate the names of the month or week, but also choose a different date format based on the language. That is, Apr 12th is ok in English, but translating Apr into Abr will not be much better in Spanish: Abr 12th - should be 12 Abr . I need to translate 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 considered there, but not the form itself. I cannot find strings like M jS , etc.

+4
source share
1 answer

You can use the drupal 7 t () function: http://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/t/7

Everything that passes through the t () function must be manually translated to the back-end Configuration> Regional and Language> Translation Interface. This means that you will have to manually transfer the transfers to days and months.

Code example:

 <?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>"); ?> 
+2
source

Source: https://habr.com/ru/post/1416121/


All Articles