store language choice in a cookie
-
Hello,
I just switched to mqtranslate from qtranslate, and I realized my little hack to keep user’s language choice in a cookie (because I use GET ?lang=fr method to switch language then stick to the chosen language) still works with mqtranslate.
Here is the mod I do, could it be included within the plugin as an option ?
in mqtranslate_core.phpreplace
if(isset($_GET['lang']) && qtrans_isEnabled($_GET['lang'])) { // language override given $result['language'] = $_GET['lang']; $result['url'] = preg_replace("#(&|\?)lang=".$result['language']."&?#i","$1",$result['url']); $result['url'] = preg_replace("#[\?\&]+$#i","",$result['url']); } elseif($home['host'] == $result['host'] && $home['path'] == $result['url']) { if(empty($referer['host'])||!$q_config['hide_default_language']) { $result['redirect'] = true; } else { // check if activating language detection is possible if(preg_match("#^([a-z]{2}).#i",$referer['host'],$match)) { if(qtrans_isEnabled($match[1])) { // found language information $referer['host'] = substr($referer['host'], 3); } } if(!$result['internal_referer']) { // user coming from external link $result['redirect'] = true; } } }
with
/* mod cookie lang */ $BSGqtc=""; if (isset($_COOKIE['BSGqTranslateForceLang'])) { $BSGqtc=$_COOKIE['BSGqTranslateForceLang']; } if( (isset($_GET['lang']) && qtrans_isEnabled($_GET['lang'])) || ($BSGqtc!="" && qtrans_isEnabled($BSGqtc)) ) { // language override given if (isset($_GET['lang'])) { setcookie ( 'BSGqTranslateForceLang', $_GET['lang'] , time()+60*60*24*365, "/" ); $BSGqtc = $_GET['lang']; } $result['language'] = $BSGqtc; $result['url'] = preg_replace("#(&|\?)lang=".$result['language']."&?#i","$1",$result['url']); $result['url'] = preg_replace("#[\?\&]+$#i","",$result['url']); } elseif($home['host'] == $result['host'] && $home['path'] == $result['url']) { if(empty($referer['host'])||!$q_config['hide_default_language']) { $result['redirect'] = true; } else { // check if activating language detection is possible if(preg_match("#^([a-z]{2}).#i",$referer['host'],$match)) { if(qtrans_isEnabled($match[1])) { // found language information $referer['host'] = substr($referer['host'], 3); } } if(!$result['internal_referer']) { // user coming from external link $result['redirect'] = true; } } } /* end mod cookie lang */
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘store language choice in a cookie’ is closed to new replies.