开发者

Drupal language negotiation

开发者 https://www.devze.com 2022-12-16 11:11 出处:网络
I have a mul开发者_开发知识库ti-language drupal setup (2 languages, english default). I want users to receive always content in the other language (lets say spanish) on initial page request, but keep

I have a mul开发者_开发知识库ti-language drupal setup (2 languages, english default). I want users to receive always content in the other language (lets say spanish) on initial page request, but keep english as default language for future language switch. So users will be redirected on initial load to site.com/es, but through the language switch will be able to go to site.com/ (which is english).

Any suggestions? Thank you.

(Apache, PHP)


Redirect users using preprocess in template.php file of your theme:
Approximate code:


/**
 * Override or insert variables into the page templates.
 *
 * @param $vars
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("page" in this case.)
 */
function THEMENAME_preprocess_page(&$vars, $hook) {
  global $language;
  if ($language->language == 'en') { // Add here some checking for page, see print_r($vars)
    drupal_goto(url().'/es/'.$GET['q']); //goto es version
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号