PostNuke

Flexible Content Management System

News

Starting page localized

Contributed by on Jun 06, 2002 - 09:11 AM

To achieve our goal, we will use a global variable named HTTP_ACCEPT_LANGUAGE which tell us the prefered language of the user.






Now we need to hack the file pnAPI.php (under the includes directory).



Go to the pnInit() function and add this line somewhere at the first lines:



global $HTTP_ACCEPT_LANGUAGE;







Now that we know what is the language that the user wants, we just need to set the PostNuke language to it or to the default site's language if we do not support it.
This can be done with a simple switch by replacing the original lines (under pnInit() function) :


this are the original lines





// Load global language defines


if (isset ($lang) && file_exists('language/' . pnVarPrepForOS($lang) . '/global.php')) {


$currentlang = $lang;


} else {


$currentlang = pnConfigGetVar('language');


pnSessionSetVar('lang', $currentlang);


}





with something like this:






This examples search for English, Spanish and German languages.





// Load global language defines


if (isset ($lang) && file_exists('language/' . pnVarPrepForOS($lang) . '/global.php')) {


$currentlang = $lang;


} else {


$BrowserLang=substr($HTTP_ACCEPT_LANGUAGE,0,2);





switch ($BrowserLang) {


case "es" :


case "ES":


$currentlang = "spa";


break;


case "en":


case "EN" :


$currentlang = "eng";


break;


case "de":


case "DE" :


$currentlang = "deu";


break;


default :


$currentlang = pnConfigGetVar('language');


} // fin del switch


pnSessionSetVar('lang', $currentlang);


}






As you can see with only a few lines of code your users will not have to click on their flag to choose their favourite language.






For those about to Nuke....we salute you


Jorge Alvarez


jalvarez at regamallorca dot com
2796