0

How to render view in specific language?

$view = views_get_view("commerce_line_items_custom");
////Pass arguments
$view->set_arguments(array($data['commerce-order']->order_id));
$view->hide_admin_links = TRUE;
////Generate content
$content =  $view->execute_display('block');

I tried following overide, but it did nothing:

$view->set_display('block');
$view->display_handler->options['field_language'] = 'fr';
$view->display_handler->display->display_options['field_language'] = 'fr';
$view->display_handler->default_display->options['field_language'] = 'fr';
$view->display_handler->set_option('field_language', 'fr');
0

May be you can try this.

function yourmodule_views_pre_render(&$views) {
  if ($views->name == 'yourviewname') { //yourviewname is the machine name of the view
    $_SESSION['language'] = fr;
  }
}
|improve this answer|||||
0

I used following solution:

      // Replace language by language of user for correct rendering of view.
      $language_list =  language_list();
      $language_org = $language;
      $language = $language_list[$lang];
      ////Get view
      $view = views_get_view("commerce_line_items_custom");
      ////Pass arguments
      $view->set_arguments(array($data['commerce-order']->order_id));
      $view->hide_admin_links = TRUE;
      ////Generate content
      $content =  $view->execute_display('block');
      $replacements[$original] = $content['content'];
      // Restore language
      $language = $language_org;
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.