Set the site display language based on browser's language on Drupal 6 and 7

Submitted by ionut on 07/06/2013
Drupal Languages Block

The other days I needed to have the language of a Drupal 6 site changed based on the user's browser language. This didn't seem to be such a daunting task but I thought that probably there is a module that does this already. Well I didn't found any module and I said to myself that this is something that I had to code although I could not believe that no one else needed this functionality until now...

So I started to write some lines of code in a hook, while throwing an eye on the Drupal API on my second monitor to see what functions are available regarding languages... (BTW if you need to check this part of the API here are the links for Drupal 7 and Drupal 6 related to language), and when I was writing my 10th line of code I remebered that in Drupal 6 there is a configuration page (admin/settings/language/configure) with a 'magic' option called Path prefix with language fallback which is the same as Determine the language from the browser's language settings from Drupal 7 (admin/config/regional/language/configure) ...

so... do I need to say more? :)

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.