You are here

function i18nviews_views_pre_view in Internationalization Views 6.2

Implementation of hook_views_pre_view().

Views are identified by $view->name.

This is just for views 2.x, next version (3.x) will use a different one

File

./i18nviews.module, line 104
Views support for Internationalization (i18n) package

Code

function i18nviews_views_pre_view(&$view, &$display_id, &$args) {
  global $language;
  if (views_api_version() == '2.0' && $language->language != language_default('language')) {

    // Also checking weird values for $display_id, see 277711
    if (!empty($view->display) && is_array($view->display) && is_string($display_id)) {
      $fields = _i18nviews_display_fields();
      if (!empty($view->display[$display_id])) {
        $fields = _i18nviews_localize_array($view->name, $display_id, $view->display[$display_id]->handler->options, $fields);
      }
      if ($fields && !empty($view->display['default'])) {
        _i18nviews_localize_array($view->name, 'default', $view->display['default']->handler->options, $fields);
      }
    }

    // Translate taxonomy fields.
    // @todo I don think this works at all.
    if (module_exists('i18ntaxonomy') && isset($view->field) && is_array($view->field)) {
      $translate = variable_get('i18ntaxonomy_vocabularies', array());
      foreach ($view->field as $index => $data) {
        $matches = array();
        if ($data['id'] == 'term_node.name') {

          // That's a full taxonomy box.
          $view->field[$index]['handler'] = 'i18ntaxonomy_views_handler_field_allterms';
        }
        elseif (preg_match("/term_node_(\\d+)\\.name/", $data['id'], $matches)) {
          $vid = $matches[1];
          if ($translate[$vid]) {

            // Set new handler for this field.
            $view->field[$index]['handler'] = 'i18ntaxonomy_views_handler_field_allterms';
          }
        }
      }
    }
  }
}