You are here

function date_locale_init in Date 6.2

Implementation of hook_init().

Initialize date formats according to the user's current locale.

File

date_locale/date_locale.module, line 12
Enable different locales to have their own date formats.

Code

function date_locale_init() {
  global $conf;
  global $language;

  // Don't do this on the general date and time formats settings page, as we
  // want to display the defaults, not the ones specific to the language we're
  // currently browsing the site in.
  if (!drupal_match_path($_GET['q'], 'admin/settings/date-time/formats')) {
    $languages = array(
      $language->language,
    );
    if (module_exists('site_country')) {
      $country_code = variable_get('site_country_default_country', '');
      if (!empty($country_code)) {
        $country_language = $language->language . '-' . $country_code;
        array_unshift($languages, $country_language);
      }
    }
    drupal_alter('date_format_languages', $languages);

    // Setup appropriate date formats for this locale.
    $formats = date_locale_get_locale_date_format($languages);
    foreach ($formats as $format_type => $format) {
      $conf[$format_type] = $format;
    }
  }
}