You are here

function date_t in Date 6

Same name and namespace in other branches
  1. 5.2 date_api.module \date_t()
  2. 6.2 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

1 call 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.

File

./date_api.module, line 453
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.
    foreach (date_month_names_untranslated() as $month) {
      $replace[$month] = t($month);
      $replace[substr($month, 0, 3)] = t(substr($month, 0, 3));
    }
    foreach (date_week_days_untranslated() as $day) {
      $replace[$day] = t($day);
      $replace[substr($day, 0, 3)] = t(substr($day, 0, 3));
    }
  }
  return strtr($string, $replace);
}