I'm not the first to ask, but I believe there must be a simple script possible so that a user can switch to another localisation (language) with a simple click. In my case, the default is French and I want English users to simply click on a link called, for example, "English navigation" (instead of asking them to create an account, etc.).

I imagine the "simplest" might be a script that identifies the default language selected in the user's browser (IE, Netscape, etc.) and tells Drupal to use that localisation for the session.

BUT it wouldn't always work, so I tried the following code proposed by Steph* a good while ago. Unfortunately, I couldn't figure out where to write "en" or "English" in the code to make it work. Yet I don't even know if this small php file would override the default language on my site.:?

Can someone tell me if this php trick would work and where to stick the "en" or "English"?

Thanks,
Mic

function locale_init() {
global $defaultLanguage,$lang,$languages;

// first set the defaultLanguage, if lang was passed in php
// initialize localization system
session_register("defaultLanguage");
if ($lang)
$defaultLanguage = $lang;

return ($languages ? ((is_object($user) && $user->id &&
$user->language) ? $user->language : $defaultLanguage ? $defaultLanguage
: key($languages)) : 0);
}

[This is followed by an html script to return to the main page of the site]

* Found at:
http://lists.drupal.org/archives/drupal-support/2002-12/msg00044.html

Comments

old mac’s picture

The easiest way to translate a page and all the contents is to pass the page to babel (altavista) translation. The translations are done by machine and can be terrible, but sometimes they are quite acceptable.

It just needs a bit of javascript.

Chris, Canada

michael_lessard_micles.biz’s picture

You got me wrong Chris,

My Drupal site uses localisation: the user can choose a language in his/her Profile and Drupal's localisation prints the 'navigational links' in the chosen language.

By a "Simple language switch", I want users to simply have to click to switch the links to the preferred language; instead of having to change it in his/her Profile.

And... it's done! Thanks to Steph.
Go to: Language Switch

Michael Lessard
webmaster of Siriel-Media - world citizens sharing news about "policies of mass destruction" (crimes against humanity, crimes of war and violent policies against civilian populations; especially those in which "we" are involved).

Michael Lessard
webmaster of Quebec City "democracy in action" media