| Topic: | Detect Visitors' Browser Language Automatically (.762) |
|---|---|
|
Slugger
Professional
Posts: 1185 Posted: |
Hi folks! Change your browser's language and go to Google. You'll see that Google has automatically detected your browser's native language. PostNuke is supposed to have a similar capability but, since this feature was included in .750, each PostNuke release has been delivered with a browser language auto-detect feature that doesn't work. The .762 release is no different. You may have set it (www.yourdomeain.com/admin.php?module=Languages&op=getConfig) and assumed it works but, unless you've fixed it, the feature is just there for looks. You can trust me on this or try it out for yourself. But don't lament over this. Fortunately, it's pretty easy to fix. Assuming you promise to back everything up, here's what you do. Open pnLang.php in your favorite editor. It can be found in your includes directory...the one in your root directory...which is to say the place where you'll find index.php, header.php, footer.php, etc. Once you've opened the file, find the following: Code// See if a language update is required $newlang = pnVarCleanFromInput('newlang'); if (!empty($newlang)) { $lang = $newlang; pnSessionSetVar('lang', $newlang); } else { $detectlang = pnConfigGetVar('language_detect'); $defaultlang = pnConfigGetVar('language'); switch ($detectlang) { case 1: // Detect Browser Language $cnvlanguage=cnvlanguagelist(); $currentlang=''; $langs = split ('[,;]',$_SERVER['HTTP_ACCEPT_LANGUAGE']); foreach ($langs as $lang) { if (file_exists('language/' . pnVarPrepForOS($cnvlanguage[$lang]) . '/global.php')) { $currentlang=$cnvlanguage[$lang]; break; } } if ($currentlang=='') $currentlang=$defaultlang; break; default: $currentlang=$defaultlang; } $lang = pnSessionGetVar('lang'); } // Load global language defines // these are deprecated and will be moved to the relevant modules // with .8x if (isset ($lang) && file_exists('language/' . pnVarPrepForOS($lang) . '/global.php')) { $currentlang = $lang; } else { $currentlang = pnConfigGetVar('language'); pnSessionSetVar('lang', $currentlang); } and replace it with the following: Code// See if a language update is required $newlang = pnVarCleanFromInput('newlang'); if (!empty($newlang)) { $lang = $newlang; pnSessionSetVar('lang', $newlang); } $lang = pnSessionGetVar('lang'); if (isset ($lang) && file_exists('language/' . pnVarPrepForOS($lang) . '/global.php')) { $currentlang = $lang; } else { $detectlang = pnConfigGetVar('language_detect'); $defaultlang = pnConfigGetVar('language'); switch ($detectlang) { case 1: // Detect Browser Language $cnvlanguage=cnvlanguagelist(); $currentlang=''; $langs = split ('[,;]',$_SERVER['HTTP_ACCEPT_LANGUAGE']); foreach ($langs as $lang) { if (file_exists('language/' . pnVarPrepForOS($cnvlanguage[$lang]) . '/global.php')) { $currentlang=$cnvlanguage[$lang]; break; } } if ($currentlang=='') $currentlang=$defaultlang; break; default: $currentlang=$defaultlang; } pnSessionSetVar('lang', $currentlang); $lang = pnSessionGetVar('lang'); } Save your file and you're good to go! Good luck and happy trails. Slugger |
|
markwest
Moderator
Posts: 7720 Posted: |
Slugger, I've re-worked the .8x language loading code albeit not in the way suggested here. Can you please check this in the next cvs daily. Also please, please log issues like this in the bug tracker. I only found this thread by accident. There's no guarentee that a bug raised in a forum post will ever be addressed. -Mark |