function date_t in Date 5.2
Same name and namespace in other branches
- 6.2 date_api.module \date_t()
 - 6 date_api.module \date_t()
 
A version of the t() function for date parts that need translation.
Run this over results of functions which do no translation of month and day names, like date() and date_format().
Parameters
string $string:
Return value
translated value of the string
2 calls to date_t()
- date_format_date in ./
date_api.module  - Reworked from Drupal's format_date function to handle pre-1970 and post-2038 dates and accept a date object instead of a timestamp as input.
 - date_order_translated in ./
date_api.module  - Helper function for BYDAY options in Date Repeat and for converting back and forth from '+1' to 'First'.
 
File
- ./
date_api.module, line 533  - This module will make the date API available to other modules. Designed to provide a light but flexible assortment of functions and constants, with more functionality in additional files that are not loaded unless other modules specifically include them.
 
Code
function date_t($string) {
  static $replace;
  if (empty($replace)) {
    $replace = array();
    // Translate the whole name first, then look for abbreviations.
    $untranslated = date_month_names_untranslated();
    foreach (date_month_names_translated() as $delta => $month) {
      $replace[$untranslated[$delta]] = $month;
      $replace[drupal_substr($untranslated[$delta], 0, 3)] = drupal_substr($month, 0, 3);
    }
    $untranslated = date_week_days_untranslated();
    foreach (date_week_days_translated() as $delta => $day) {
      $replace[$untranslated[$delta]] = $day;
      $replace[drupal_substr($untranslated[$delta], 0, 3)] = drupal_substr($day, 0, 3);
    }
  }
  return strtr($string, $replace);
}