Last active
December 20, 2015 01:19
-
-
Save walterdavis/6048699 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jar = new CookieJar({path: '/', expires: 31536000}), | |
// change these to match your site | |
en = 'example.com/en', | |
fr = 'example.com/fr', | |
// don't change this line or below | |
matcher = new RegExp([en, '|', fr].join('').gsub('.','\\.')); | |
// did they already set a preference? | |
var preferred = jar.get('language'); | |
if(!!preferred){ | |
if(!window.location.href.toString().include(preferred)){ | |
window.location.replace(window.location.href.toString().replace(matcher, preferred)); | |
} | |
} | |
// handle user input to change the language | |
document.on('click', '.language', function(evt, elm){ | |
if(elm.hasClassName('en')) | |
jar.set('language',en); | |
if(elm.hasClassName('fr')) | |
jar.set('language',fr); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment