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. *
Authorplauclair
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.

Instructions

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

README

AutodetectLanguage

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

Configuration

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.

Changes

1.0.3

  • 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.

1.0.2

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

1.0.1

  • 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.

1.0.0

  • 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".

Support

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

Licence

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

Comments

  • Dominik Lenné

    Dominik Lenné 2 years ago 10

    Hi,

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

    Thanks for considering

    Dominik

    • Pierre-Luc

      Pierre-Luc 2 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 4 months ago 10

    Hi, is there any plan to update this?

Post a Comment

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