function getLocale(){ var getLocaleStr = "en"; if(typeof Cookies.get('locale') == 'undefined'){ if(window.navigator.language.match(/^[a-z][a-z]/gi)){ getLocaleStr=window.navigator.language.substring(0,2);; }else{ getLocaleStr="en"; } }else if(typeof Cookies.get('locale') == "string"){ if(Cookies.get('locale').match(/^[a-z][a-z]$/)){ getLocaleStr=Cookies.get('locale'); }else{ getLocaleStr="en"; } } return getLocaleStr; } function pushLocale(){ // Loop through every ".locale" and pull in the wording $('.locale').each(function(id, obj){ $(this).html(language[$(this).attr('id')]); }); $('.localehref').each(function(id, obj){ $(this).text(language[$(this).attr('id')]); }); } function changeLocale(language){ $.getScript( "/locale/"+language+".js") .done(function( script, textStatus ) { pushLocale(); }) .fail(function( jqxhr, settings, exception ) { if(arguments[0].readyState==0){ console.log("ERROR: failed to load locale"); }else{ console.log("ERROR: "+arguments[2].toString()); } }); } function setLocale(locale){ Cookies.set('locale', locale, {expires: 30,domain: '.7blessings.co.uk' }); changeLocale(locale); }