set_arguments(array($data['commerce-order']->order_id));$view->hide_admin_links " />

Render view in specific language

2017-09-21 09:26:29

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');

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;

}

}

I used following solution:

// Replace language by language of user for correct rendering of view.

$language_list = language_list();

  • 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;

    }

    }

    2017-09-21 09:38:18
  • 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;

    2017-09-21 10:30:43