1
votes

I have a multi-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)

1
can we do also something else for you? A Sandwich? A cold Cola? or a Beer? ;-) - streetparade
almost funny. I asked for suggestions not code. but now that you offered, please a beer. double time :-) - spk
Ok here is your cold Beer |__|) - streetparade
May be you should save the spanish language in a cookie and if you want to redirect to the english site destroy the content of the coockie value not the cookie it self but just the value you have set like unset($_COOKIE['isspanish']); - streetparade
it is not as trivial as it seems :-). go grab a beer and relax. - spk

1 Answers

1
votes

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
  }
}