You are here

function locale_css_alter in Drupal 7

Implements hook_css_alter().

This function checks all CSS files currently added via drupal_add_css() and and checks to see if a related right to left CSS file should be included.

File

modules/locale/locale.module, line 963
Add language handling functionality and enables the translation of the user interface to languages other than English.

Code

function locale_css_alter(&$css) {
  global $language;

  // If the current language is RTL, add the CSS file with the RTL overrides.
  if ($language->direction == LANGUAGE_RTL) {
    foreach ($css as $data => $item) {

      // Only provide RTL overrides for files.
      if ($item['type'] == 'file') {
        $rtl_path = str_replace('.css', '-rtl.css', $item['data']);
        if (file_exists($rtl_path) && !isset($css[$rtl_path])) {

          // Replicate the same item, but with the RTL path and a little larger
          // weight so that it appears directly after the original CSS file.
          $item['data'] = $rtl_path;
          $item['weight'] += 0.0001;
          $css[$rtl_path] = $item;
        }
      }
    }
  }
}