Skip to content

Commit

Permalink
Code comment
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Aug 17, 2011
1 parent ee791f1 commit 55367f8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
28 changes: 16 additions & 12 deletions htdocs/core/class/translate.class.php
Expand Up @@ -23,7 +23,7 @@
* \brief File for Tanslate class
* \author Eric Seigne
* \author Laurent Destailleur
* \version $Id: translate.class.php,v 1.50 2011/08/15 23:17:14 eldy Exp $
* \version $Id: translate.class.php,v 1.51 2011/08/17 21:41:24 eldy Exp $
*/


Expand All @@ -35,16 +35,16 @@ class Translate {

var $dir; // Directories that contains /langs subdirectory

var $defaultlang; // Langue courante en vigueur de l'utilisateur
var $defaultlang; // Current language for current user
var $direction = 'ltr'; // Left to right or Right to left
var $charset_inputfile=array(); // To store charset encoding used for language
var $charset_output='UTF-8'; // Codage used by "trans" method outputs

var $tab_translate=array(); // Tableau des traductions
var $tab_translate=array(); // Array of all translations key=>value
var $tab_loaded=array(); // Array to store result after loading each language file

var $cache_labels=array(); // Cache for labels
var $cache_labels=array(); // Cache for labels return by trans method

var $charset_inputfile=array(); // To store charset encoding used for language
var $charset_output='UTF-8'; // Codage used by "trans" method outputs


/**
Expand All @@ -62,7 +62,6 @@ function Translate($dir = "",$conf)
}



/**
* Set accessor for this->defaultlang
*
Expand Down Expand Up @@ -220,7 +219,7 @@ function Load($domain,$alt=0,$stopafterdirection=0,$forcelangdir='')
// Using a memcached server
if (! empty($conf->memcached->enabled) && ! empty($conf->global->MEMCACHED_SERVER))
{
$usecachekey=$newdomain.'_'.$langofdir.'_'.$file_lang;
$usecachekey=$newdomain.'_'.$langofdir.'_'.md5($file_lang); // Should not contains special chars
}
// Using cache with shmop. Speed gain: 40ms - Memory overusage: 200ko (Size of session cache file)
else if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02))
Expand Down Expand Up @@ -268,7 +267,7 @@ function Load($domain,$alt=0,$stopafterdirection=0,$forcelangdir='')
}
elseif ($key == 'DIRECTION') // This is to declare direction of language
{
if ($alt < 2 || empty($this->tab_translate[$key])) // We load direction only for primary files or if not yer load
if ($alt < 2 || empty($this->tab_translate[$key])) // We load direction only for primary files or if not yet loaded
{
$this->tab_translate[$key]=$value;

Expand All @@ -279,7 +278,7 @@ function Load($domain,$alt=0,$stopafterdirection=0,$forcelangdir='')
else
{
// On stocke toujours dans le tableau Tab en UTF-8
if (empty($this->charset_inputfile[$newdomain]) || $this->charset_inputfile[$newdomain] == 'ISO-8859-1') $value=utf8_encode($value);
if (! empty($this->charset_inputfile[$newdomain]) && $this->charset_inputfile[$newdomain] == 'ISO-8859-1') $value=utf8_encode($value);

//print 'XX'.$key;
$this->tab_translate[$key]=$value;
Expand All @@ -296,11 +295,16 @@ function Load($domain,$alt=0,$stopafterdirection=0,$forcelangdir='')
if ($usecachekey && sizeof($tabtranslatedomain))
{
require_once(DOL_DOCUMENT_ROOT ."/lib/memory.lib.php");
$size=dol_setcache($usecachekey,$tabtranslatedomain);
$ressetcache=dol_setcache($usecachekey,$tabtranslatedomain);
if ($ressetcache < 0)
{
$error='Failed to set cache for usecachekey='.$usecachekey.' result='.$ressetcache;
dol_syslog($error, LOG_ERR);
}
}
//exit;

if (empty($conf->global->MAIN_FORCELANGDIR)) break; // Break loop on each root dir. If a module has forced, we do not stop loop.
if (empty($conf->global->MAIN_FORCELANGDIR)) break; // Break loop on each root dir. If a module has forced dir, we do not stop loop.
}
}
}
Expand Down
28 changes: 16 additions & 12 deletions htdocs/lib/memory.lib.php
Expand Up @@ -19,7 +19,7 @@
/**
* \file htdocs/lib/memory.lib.php
* \brief Set of function for memory/cache management
* \version $Id: memory.lib.php,v 1.11 2011/07/31 23:25:11 eldy Exp $
* \version $Id: memory.lib.php,v 1.12 2011/08/17 21:39:08 eldy Exp $
*/

global $shmkeys,$shmoffset;
Expand All @@ -34,10 +34,11 @@


/**
* \brief Save data into a memory area shared by all users, all sessions on server
* \param $memoryid Memory id of shared area
* \param $data Data to save
* \return int <0 if KO, Nb of bytes written if OK
* Save data into a memory area shared by all users, all sessions on server
*
* @param $memoryid Memory id of shared area
* @param $data Data to save
* @return int <0 if KO, Nb of bytes written if OK
*/
function dol_setcache($memoryid,$data)
{
Expand All @@ -52,7 +53,8 @@ function dol_setcache($memoryid,$data)
$tmparray=explode(':',$conf->global->MEMCACHED_SERVER);
$result=$m->addServer($tmparray[0], $tmparray[1]?$tmparray[1]:11211);
//$m->setOption(Memcached::OPT_COMPRESSION, false);
$m->add($memoryid,$data);
//print "Add memoryid=".$memoryid;
$m->add($memoryid,$data); // This fails if key already exists
$rescode=$m->getResultCode();
if ($rescode == 0)
{
Expand All @@ -70,7 +72,7 @@ function dol_setcache($memoryid,$data)
$tmparray=explode(':',$conf->global->MEMCACHED_SERVER);
$result=$m->addServer($tmparray[0], $tmparray[1]?$tmparray[1]:11211);
//$m->setOption(Memcached::OPT_COMPRESSION, false);
$result=$m->add($memoryid,$data);
$result=$m->add($memoryid,$data); // This fails if key already exists
if ($result)
{
return sizeof($data);
Expand All @@ -90,9 +92,10 @@ function dol_setcache($memoryid,$data)
}

/**
* \brief Read a memory area shared by all users, all sessions on server
* \param $memoryid Memory id of shared area
* \return int <0 if KO, data if OK
* Read a memory area shared by all users, all sessions on server
*
* @param $memoryid Memory id of shared area
* @return int <0 if KO, data if OK
*/
function dol_getcache($memoryid)
{
Expand All @@ -106,9 +109,10 @@ function dol_getcache($memoryid)
$tmparray=explode(':',$conf->global->MEMCACHED_SERVER);
$result=$m->addServer($tmparray[0], $tmparray[1]?$tmparray[1]:11211);
//$m->setOption(Memcached::OPT_COMPRESSION, false);
//print "Get memoryid=".$memoryid;
$data=$m->get($memoryid);
$rescode=$m->getResultCode();
//print "memoryid=".$memoryid." - rescode=".$rescode." - date=".sizeof($data)."\n<br>";
//print "memoryid=".$memoryid." - rescode=".$rescode." - data=".sizeof($data)."\n<br>";
//var_dump($data);
if ($rescode == 0)
{
Expand All @@ -127,7 +131,7 @@ function dol_getcache($memoryid)
$result=$m->addServer($tmparray[0], $tmparray[1]?$tmparray[1]:11211);
//$m->setOption(Memcached::OPT_COMPRESSION, false);
$data=$m->get($memoryid);
//print "memoryid=".$memoryid." - rescode=".$rescode." - date=".sizeof($data)."\n<br>";
//print "memoryid=".$memoryid." - rescode=".$rescode." - data=".sizeof($data)."\n<br>";
//var_dump($data);
if ($data)
{
Expand Down

0 comments on commit 55367f8

Please sign in to comment.