function _format_date_callback

Translates a formatted date string.

Callback for preg_replace_callback() within format_date().

Related topics

1 call to _format_date_callback()
DrupalDateTime::format in drupal/core/lib/Drupal/Core/Datetime/DrupalDateTime.php
Overrides format().
1 string reference to '_format_date_callback'
DrupalDateTime::format in drupal/core/lib/Drupal/Core/Datetime/DrupalDateTime.php
Overrides format().

File

drupal/core/includes/common.inc, line 1304
Common functions that many Drupal modules will need to reference.

Code

function _format_date_callback(array $matches = NULL, $new_langcode = NULL) {

  // We cache translations to avoid redundant and rather costly calls to t().
  static $cache, $langcode;
  if (!isset($matches)) {
    $langcode = $new_langcode;
    return;
  }
  $code = $matches[1];
  $string = $matches[2];
  if (!isset($cache[$langcode][$code][$string])) {
    $options = array(
      'langcode' => $langcode,
    );
    if ($code == 'F') {
      $options['context'] = 'Long month name';
    }
    if ($code == '') {
      $cache[$langcode][$code][$string] = $string;
    }
    else {
      $cache[$langcode][$code][$string] = t($string, array(), $options);
    }
  }
  return $cache[$langcode][$code][$string];
}