Drupal 6 language selection algorithm in "Path prefix with language fallback" mode

Submitted by boaz on Saturday, March 28, 2009.

Are you in a need to alter Drupal 6 language selection algorithm?Do you just need to know what's going on under the hood? Well, you've landed on the right article. I've recently needed to do the first task, and of course you can't change something unless you know how it works in the first place. Its actually pretty simple. Here's how Drupal 6 determines the language:

  • First, some background: For those of you who don't know it by now, on each request Drupal handles (note - images and other files are handled by Apache - not Drupal) Drupal goes through a "bootstrap" process. In a nutshell, this means goes through several preliminary tasks to do in the beginning. Among those are load page from cache, if appropriate, check access permissions to the relevant page, and more. We'll focus here on "language selection" task that is also performed at that stage.
  • Algorithm? Algorithms: Actually, Drupal have several options (="algorithms") you can choose from, to decide on how to determine language. This is configurable on admin/settings/language/configure. See some words on this here, but I have to admit I don't have a ready made link for good documentation on this exact configuration screen (suggestions are welcome!).
  • Algorithm in "Path prefix with language fallback" mode: 

    /** Pseudo code below...**/
    if (lang prefix in URL patches any of the site's enabled languages) {

        use that language.
    else if ($user has language property set and its valid (exists as a valid language in site's enable languages)) {

        use that language }
    else if (browser sent supported language that appears in site's enable languages) {

        use that language }
    else {

        use site default language
  • The full information, and at the end of the only information you can trust on is found, of course, in the source code itself. See includes/language.inc (language_initialize())


Leave a Comment

Fields with * are required.