Skip to content
Craft plugin for detecting user language preferences and redirecting to the appropriate locale.
Branch: master
Clone or download
Pull request Compare This branch is 4 commits ahead, 8 commits behind vigetlabs:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Locale Redirector plugin for Craft CMS

Locale Redirector detects the language preferences set by the user, via cookie or browser settings, and redirects to the appropriate localized version of the page requested, if the locale has been enabled for the site.

  1. Cookie: If the user's language preference has been saved in a cookie named locale, and the requested url is for a different locale currently enabled for the site, the user will be redirected to the locale saved in the cookie, for the requested url. For example:
Requested URL:
Cookie Present: es
Configured Site Locales: en, fr, de, pt, es
Redirects To:
  1. Browser Language Settings: If the language preference has not yet been saved to a cookie, then the plugin will attempt to find a match between the browser's preferred languages and the site's enabled locales. If a match is found, the user will be redirected to the matched language setting. For example:
Requested URL:
Cookie Present: n/a
Browser Languages: es, en
Configured Site Locales: en, fr, de, pt, es
Redirects To:


To install Locale Redirector, follow these steps:

  1. Download & unzip the file and place the localeredirector directory into your craft/plugins directory
  2. -OR- do a git clone directly into your craft/plugins folder. You can then update it with git pull
  3. Install plugin in the Craft Control Panel under Settings > Plugins
  4. The plugin folder should be named localeredirector for Craft to see it. GitHub recently started appending -master (the branch name) to the name of the folder for zip file downloads.

Locale Redirector works on Craft 2.5.x and Craft 2.6.x.

Important Notes

This plugin assumes that language links are available to the user. You can build this list of links any way you want, using custom template code with advanced logic, but the simplest approach is to use a craft plugin called Language Link. It provides an easy way to switch between languages by automatically outputting the correct links to the same page in different locales.

You can then set a locale cookie when one of these links is clicked, via JavaScript. You can use document.cookie for this, or use the js-cookie utility, which couldn't be simpler. To set a locale cookie to "es" and have it exipre in 1 year:

Cookies.set('locale', 'es', { expires: 365 });


Some things to do, and ideas for potential features:

  • Make locale cookie name and expiration configurable


1.0.0 -- 2016.10.03

  • Initial release
Code At Viget

Visit to see more projects from Viget.

You can’t perform that action at this time.