Multi language

gmcms

No avatar

2005-09-12 22:45

Hi all,
I test a modif to have a multi- lang frontend. I know ... it's not multi-lang content, but I think that it's important to understand the front end if you want to buy products for which there are pics instead of explanation in your native language.

I show you the hack. All expert comments are welcome !

In index.php you add just after extract( $_GET );

-----------------------------------
if( !function_exists( 'detect_language' ) ){
function detect_language() {


$available_languages = array(

'de' => array('de([-_][[:alpha:]]{2})?|german', 'german'),

'en' => array('en([-_][[:alpha:]]{2})?|english', 'english'),

'es' => array('es([-_][[:alpha:]]{2})?|spanish', 'spanish'),

'fr' => array('fr([-_][[:alpha:]]{2})?|french', 'french'),

'it' => array('it|italian', 'italian'),

);


define('COOKIE_TIME', 86400 * 30);

if (isset($_GET['l'])) {
$accepted_language[0] = htmlentities($_GET['l']);
} else {
if(!empty($_COOKIE['cookie_lang'])) {
$accepted_language[0] = $_COOKIE['cookie_lang'];
}else{
$accepted_language = explode(',', getenv('HTTP_ACCEPT_LANGUAGE'));
}

}

$detected_language = LANGUAGE;

$cnt = 0;



while ($cnt < sizeof($accepted_language)) {

reset($available_languages);



while (list($key, $value) = each($available_languages)) {

if ((eregi('^(' . $value[0] . ')(;q=[0-9]\\.[0-9])?$', $accepted_language[$cnt]))) {

$detected_language = $key;

break 2;

}

}

$cnt++;

}


setcookie('cookie_lang', $detected_language, time() + COOKIE_TIME);


return $detected_language;

}

}

// compute language choice
$ltu = detect_language();
if (file_exists(DIR_LANG.$ltu.'.php')) { // include the right language file
require_once DIR_LANG.$ltu.'.php';
} else {
require_once DIR_LANG.LANGUAGE.'.php'; // default language file to config
}
-----------------------------------

In index.php you delete the line require_once DIR_LANG.LANGUAGE.'.php';

So you can :
- detect the prefered language of your browser and check with the languages you choose in $available_languages array
- look at your cookie
- accept index.php?l=xx

Have fun

Senior Security Network Consultant

gmcms

No avatar

2005-09-12 22:48

I ask a question to myself : is it possible to do the same thing in plugin ? I don't know how to transform this hack in plugin. It seems to be difficult without changing anything in the core code.

Senior Security Network Consultant

re-aktor

No avatar

2006-09-13 16:51

doesnt work for me... just

Error:
Warning: require_once(DIR_LANGLANGUAGE.php) [function.require-once]: failed to open stream: No such file or directory in /srv/www/htdocs/web211/html/shoptest/index.php on line 78

Fatal error: require_once() [function.require]: Failed opening required 'DIR_LANGLANGUAGE.php' (include_path='.:/usr/local/php5/lib/php:/srv/www/htdocs/confixx/html:/srv/www/htdocs/confixx/html/include') in /srv/www/htdocs/web211/html/shoptest/index.php on line 78

mhh i would like to get an english one too.....

bron

No avatar

2006-09-13 23:53

require_once(DIR_LANG. LANGUAGE.php) will probably working


re-aktor

No avatar

2006-09-14 05:14

mhh no that doesnt work but ive got an idea which works for me! i have to copy the snippet of gmcms to another place (where normaly the require_once DIR_LANG.LANGUAGE.'.php'; is) and then it works!!!

here is the whole index.php:


<?php
/*
* Quick.Cart by OpenSolution.org
* www.opensolution.org
*/
extract$_GET );


require 
'config/general.php';

if( !isset( 
$p ) || $p == '' ){
  
$p  $config['start_page'];
}

if( 
ereg'Window'$p ) ){
  
$p          ereg_replace'Window'''$p );
  
$bPrint     true;
  
$sBlockPage '_PRINT';
}
elseif( 
ereg'Gallery'$p ) ){
  
$p          ereg_replace'Gallery'''$p );
  
$bGallery   true;
  
$sBlockPage '_GALLERY';
}

if( !isset( 
$iCategory ) )
  
$iCategory null;

if( !
function_exists'detect_language' ) ){
function 
detect_language() {


$available_languages = array(

'de' => array('de([-_][[:alpha:]]{2})?|german''german'),

'en' => array('en([-_][[:alpha:]]{2})?|english''english'),

);


define('COOKIE_TIME'86400 30);

if (isset(
$_GET['l'])) {
$accepted_language[0] = htmlentities($_GET['l']);
} else {
if(!empty(
$_COOKIE['cookie_lang'])) {
$accepted_language[0] = $_COOKIE['cookie_lang'];
}else{
$accepted_language explode(','getenv('HTTP_ACCEPT_LANGUAGE'));
}

}

$detected_language LANGUAGE;

$cnt 0;



while (
$cnt sizeof($accepted_language)) {

reset($available_languages);



while (list(
$key$value) = each($available_languages)) {

if ((
eregi('^(' $value[0] . ')(;q=[0-9]\\.[0-9])?$'$accepted_language[$cnt]))) {

$detected_language $key;

break 
2;

}

}

$cnt++;

}


setcookie('cookie_lang'$detected_languagetime() + COOKIE_TIME);


return 
$detected_language;

}

}

// compute language choice
$ltu detect_language();
if (
file_exists(DIR_LANG.$ltu.'.php')) { // include the right language file
require_once DIR_LANG.$ltu.'.php';
} else {
require_once(
DIR_LANGLANGUAGE.php); // default language file to config
}


require_once 
DIR_LIBRARIES.'TplParser.php';
require_once 
DIR_LIBRARIES.'FileJobs.php';
require_once 
DIR_LIBRARIES.'FlatFiles.php';
require_once 
DIR_LIBRARIES.'Trash.php';

if( isset( 
$sWord ) && !empty( $sWord ) )
  
$sWord htmlspecialcharschangeSpecialCharsstripslashes$sWord ) ) );

/*
* Add-ons functions
*/
if( filesizeDIR_PLUGINS.'plugins.php' ) > 30 )
  require 
DIR_PLUGINS.'plugins.php';

$tpl    = new TplParser;
$oFF    = new FlatFiles;
$contentnull;
$tpl->setDirTPL );

require_once 
DIR_CORE.'other.php';
require_once 
DIR_CORE.'categories-'.$config['db_type'].'.php';
require_once 
DIR_CORE.'categories.php';

/*
* Add-ons actions
*/
if( filesizeDIR_PLUGINS.'actions_client.php' ) > 30 )
  require 
DIR_PLUGINS.'actions_client.php';

getAction$p'actions_client/' );

if( 
is_file$sActionFile ) )
  require_once 
$sActionFile;
else{
  require_once 
DIR_CORE.'files-'.$config['db_type'].'.php';
  require_once 
DIR_CORE.'files.php';

  if( !isset( 
$bDisplayedPage ) ){
    if( 
strlen$p ) > )
      
$iCategory substr$p);

    if( !
is_numeric$iCategory ) )
      
$iCategory $config['contact_page'];

    
$aData throwCategory$iCategorytruetrue );

    if( !isset( 
$aData['sDescriptionFull'] ) ){
      
$iCategory  $config['contact_page'];
      
$aData      throwCategory$iCategorytruetrue );
    }

    
$sBlock         'COLUMNS_ONE';
    
$sTitleBefore   $aData['sName'].' - ';
    
$sSubcategories listCategoriesChildren$iCategory'contents_more.tpl'true );
    
$aFiles         listFiles$iCategory'contents_more.tpl');

    if( 
$iCategory == $config['contact_page'] ){
      if( isset( 
$_POST['sSend'] ) )
        
$sContentPanel =  sendEmail$_POST'contact.tpl' );
      else
        
$sContentPanel =  $tpl->tbHtml'contact.tpl''FORM' );
      
$sBlock 'COLUMNS_TWO_CONTACT';
    }
    else{
      if( isset( 
$aFiles['sPhotosDefault'] ) )
        
$sContentPanel $aFiles['sPhotosDefault'];
      if( isset( 
$aFiles['sPhotos'] ) )
        
$sContentPanel .= $aFiles['sPhotos'];
      
      if( isset( 
$sContentPanel ) && !empty( $sContentPanel ) )
        
$sBlock 'COLUMNS_TWO';
    }
    
$content .= $tpl->tbHtml'contents_more.tpl'$sBlock );
  }
}

if( !isset( 
$sBlockPage ) ){
  if( !isset( 
$sCategoriesMenu ) )
    
$sCategoriesMenu listCategories'categories_menu.tpl'1true, Array( $iCategory ) );
  if( !isset( 
$sContentsMenu ) )
    
$sContentsMenu listCategories'contents_menu.tpl'2true, Array( $iCategory ) );
  
$sBlockPage null;
}

echo 
$tpl->tbHtml'page.tpl''HEAD'.$sBlockPage ).$content.$tpl->tbHtml'page.tpl''FOOTER'.$sBlockPage );
?>

Back to top
about us | contact