About Autodetect Language

Finds a best match between visitor's language and redirects automatically.

Category Language Modules
Modules involved in providing multi-language support.
Release StateStable
Should be safe for use in production environments. *
Module Version1.0.3
Class NameAutodetectLanguage
Compatibility2.5, 2.6, 2.7
Date AddedJanuary 9, 2015
Last UpdatedMay 11, 2015
Recommended ByNew recommendations may take up to 1 day to appear.


This module's files should be placed in /site/modules/AutodetectLanguage/
How to install or uninstall modules



This ProcessWire 2.x module tries finds a best match between HTTP_ACCEPT_LANGUAGE and currently installed languages.

If a match is found, the user will be redirected from the requested page to the same page in his preferred language. This match occurs only on the first page load, and will work with default caching on.

For example:

  • User requests http://example.com/fr/a-propos
  • Module detects a preference for English. At first, the module tries to do a "full match" using the full language name (e.g. en-US -> en-US). If no match is found, it will fall back to a "partial match" using only the first part of the name (e.g. fr-CA -> fr-FR, matched with "fr" only).
  • User is redirected to http://example.com/en/about

The module creates two ProcessWire session variables:

  • $session->languageAlreadyDetected returns true if detection has run once
  • $session->languageDetectionFailed returns true if fell back to default


Set the language code for the "default" language in Modules > Autodetect Language.

You must also use BCP 47 formatted language codes as your language names. These are the typical us or en-US you commonly see. If not set, will default back to "en".

It is possible to have the redirect happen only on the homepage by checking Only detect language on homepage in module settings.

Additionally, you can set a GET parameter to prevent language redirection on some requests with Do not detect language if GET parameter is set.



  • This version introduces a new option: "Do not detect language if GET parameter is set". Usage info can be found in the Configuration section of this document.


  • Add check if isset http_accept_language that could cause a warning if the website is requested through a REST call, for example.


  • Removed debug stuff.
  • Add option to detect the user language only on the homepage.
  • Do not redirect if the requested page is already using the best language match.


  • Initial commit.

You must also use BCP 47 formatted language codes as your language names. These are the typical us or en-US you commonly see. If not set, will default back to "en".


Please use the bug tracker to submit bugs and feature requests.


Licensed under the MIT License (MIT). Copyright © 2014 Pierre-Luc Auclair


  • Dominik Lenné

    Dominik Lenné 3 years ago 10


    I would find this module very important, if it would work with PW v. 3.x

    Thanks for considering


    • Pierre-Luc

      Pierre-Luc 3 years ago 10

      Hi Dominik,

      Support for 3.x will come, but I am waiting for an announcement of 3.x becoming a stable branch to add support.

  • Saverio

    Saverio 2 years ago 10

    Hi, is there any plan to update this?

  • Horst

    Horst 2 years ago 10

    Hi Pierre-Luc, does it now work with PW 3.X ?
    Thanks in advance

  • Horst

    Horst 1 year ago 00

    Earth to Pierre-Luc.. :-)
    What about PW 3.X ?
    Thank you!

  • Horst

    Horst 1 year ago 00

    btw...yes, it's another Horst ;)

Post a Comment

Your e-mail is kept confidential and not included with your comment. Website is optional.