Good news / Bonne nouvelle !
Users no longer need to choose a language in the Profile (nor to create an account beforehand)
Les usagers n'ont plus besoin de choisir une langue dans le Profil (ni de créer un compte auparavant)
Thanks to Steph's patch (I'm just a tester)...
People visiting your site can choose their preferred language at the start and with a simple click in a Block (optionnal of course).
Les gens qui visitent votre site peuvent choisir le langage de leur choix au départ and par un simple 'clique' dans un Bloc (optionnel évidemment)
For/Pour Drupal 4.2 :
- you can download the patched files with the following link (you have a bit of config to do in common.inc —explained in the file— and insert your database info in conf.php as normal).
- vous pouvez télécharger les fichiers modifiés au lien ci-dessous (vous avez un peu de config à faire dans common.inc —expliqué dans le fichier— et entrez vos info dans conf.php comme à la normal).
www.droitvp.org/language-switch/
Cheers ! :D
Comments
Re: Language switch (on Homepage & Block)
The conf.php (patched for the 'Language switch' could not be downloaded for some reason. I fixed this by adding .txt in the file name.
Enjoy,
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; e
Michael Lessard
webmaster of Quebec City "democracy in action" media
Simple hack
Thanks for posting your code.
I'm building a japanese-english intranet and I needed something that can :
Your code pointed me in the right direction.
I ended up writing my own code by hacking locale_init() and creating a simple block module that listed the languages and set the "locale" cookie when you click on the link.
Here's the hack of locale_init() that works for me.
#includes/common.inc function locale_init() { global $languages, $user; // START HACK // If locale has been set, it just sticks with it. if ($_COOKIE["locale"]) { return $_COOKIE["locale"]; } // At startup, locale is setup from the browser languages // if there is a match foreach ($languages as $key => $val) { $lang_match[] = $key; } preg_match("/(" . implode("|",$lang_match) .")/",$_SERVER "HTTP_ACCEPT_LANGUAGE"], $matches); if($matches) { return $matches[0]; } //END OF HACK //otherwise it just goes with the normal selection process. if ($user->uid && $languages[$user->language]) { return $user->language; } else { return key($languages); } }looks good
my one comment is that your edit should move down, between the if ...else ... statements below. If a user explicitly picks a language, he should get that language irrespective of what the brwoser is requesting.
Another possible issue
Another possible issue is that people often do not have a single language defined, but many.
A person from Egypt for example could have this HTTP_ACCEPT_LANGUAGE variable set to "en-us,ar-eg;", which means he browses in English and in Arabic.
My understanding of your code, is that it will only return the first match, which may not be what the user wants.
A great feature though for end users!
--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba
Other way around
Usually, you have your languages set in the priority order.
I have it set to "sv-se,en-us" to get the page in Swedish. If that's not possible, then fallback to English.
Some info about Apache's content negotiation.
Cookie setting block.
raphaelr,
Could you by any chance post the code that you used to create the cookie setting block (i.e. to swap languages)? I've tried to cobble together a block with the standard Drupal look-and-feel & with appropriate hyperlinks but without sucess - I'm no PHP expert!
A note for anyone trying to use the code above: $_SERVER "HTTP_ACCEPT_LANGUAGE"] should read $_SERVER["HTTP_ACCEPT_LANGUAGE"]
Works in 4.3 ??
Since I'm rewriting my portal using Drupal 4.3, is this hack available also for thre new version ??
Thanks
Matteo
mailto:webmaster@cantincoro.org
403 Forbidden
looks like you've got some permission errors on that directory...
i too have patched locale_init() for a couple fr/en sites in canada.
what's the hold-up getting a patch like this into core?
--
James Walker :: http://walkah.net/
A module now replaces all this !
The i18n.module replaces all these hacks and the 'language switch'. My tests show that version 1.0 of the i18n.module works with Drupal 4.3 (the block won't work, but the automatic "browser-language" setting works fine).
But the module will work completely with Drupal 4.4.
See forum discussion : http://drupal.org/node/view/6377
( I haven't tested it with Drupal 4.2. )
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)
Michael Lessard
webmaster of Quebec City "democracy in action" media
Does anyone still have the code for this hack?
I know this thread is ancient history, but I have a need for a block that does something very similar. I basically want to present some radio buttons in a block that let a user select their timezone (US only, so 4 choices). Then I want to update a cookie with that value for use site-wide.
Does anyone have the code the original poster wrote? Or can you recommend a similar module that I can modify for my needs?
thanks,
Phil