Perf: Yeah. Won again 3ms at each page call.
This commit is contained in:
parent
dc447f6aa0
commit
94910d8c73
@ -415,50 +415,45 @@ class Translate {
|
|||||||
*/
|
*/
|
||||||
function trans($key, $param1='', $param2='', $param3='', $param4='', $maxsize=0)
|
function trans($key, $param1='', $param2='', $param3='', $param4='', $maxsize=0)
|
||||||
{
|
{
|
||||||
global $mysoc;
|
|
||||||
|
|
||||||
if (! empty($this->tab_translate[$key])) // Translation is available
|
if (! empty($this->tab_translate[$key])) // Translation is available
|
||||||
{
|
{
|
||||||
$str=preg_replace('/\\\"/','"',$this->tab_translate[$key]); // To solve some translation keys containing key=abc\"def\"ghi instead of abc"def"ghi
|
//$str=preg_replace('/\\\"/','"',$this->tab_translate[$key]); // To solve some translation keys containing key=abc\"def\"ghi instead of abc"def"ghi
|
||||||
|
$str=$this->tab_translate[$key];
|
||||||
|
|
||||||
if (! preg_match('/^Format/',$key)) $str=sprintf($str,$param1,$param2,$param3,$param4); // Replace %s and %d except for FormatXXX strings.
|
if (! preg_match('/^Format/',$key)) $str=sprintf($str,$param1,$param2,$param3,$param4); // Replace %s and %d except for FormatXXX strings.
|
||||||
if ($maxsize) $str=dol_trunc($str,$maxsize);
|
if ($maxsize) $str=dol_trunc($str,$maxsize);
|
||||||
// On remplace les tags HTML par __xx__ pour eviter traduction par htmlentities
|
// On remplace les tags HTML par __xx__ pour eviter traduction par htmlentities
|
||||||
$newstr=str_replace('<','__lt__',$str);
|
$str=str_replace(array('<','>','"',),array('__lt__','__gt__','__quot__'),$str);
|
||||||
$newstr=str_replace('>','__gt__',$newstr);
|
|
||||||
$newstr=str_replace('"','__quot__',$newstr);
|
|
||||||
|
|
||||||
$newstr=$this->convToOutputCharset($newstr); // Convert string to $this->charset_output
|
$str=$this->convToOutputCharset($str); // Convert string to $this->charset_output
|
||||||
|
|
||||||
// Cryptage en html de la chaine
|
// Cryptage en html de la chaine
|
||||||
// $newstr est une chaine stockee en memoire au format $this->charset_output
|
// $str est une chaine stockee en memoire au format $this->charset_output
|
||||||
$newstr=htmlentities($newstr,ENT_QUOTES,$this->charset_output);
|
$str=htmlentities($str,ENT_QUOTES,$this->charset_output);
|
||||||
|
|
||||||
// On restaure les tags HTML
|
// On restaure les tags HTML
|
||||||
$newstr=str_replace('__lt__','<',$newstr);
|
$str=str_replace(array('__lt__','__gt__','__quot__'),array('<','>','"',),$str);
|
||||||
$newstr=str_replace('__gt__','>',$newstr);
|
return $str;
|
||||||
$newstr=str_replace('__quot__','"',$newstr);
|
|
||||||
return $newstr;
|
|
||||||
}
|
}
|
||||||
else // Translation is not available
|
else // Translation is not available
|
||||||
{
|
{
|
||||||
$newstr=$this->getTradFromKey($key);
|
$str=$this->getTradFromKey($key);
|
||||||
return $this->convToOutputCharset($newstr);
|
return $this->convToOutputCharset($str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Return translated value of a text string
|
* Return translated value of a text string
|
||||||
* Si il n'y a pas de correspondance pour ce texte, on cherche dans fichier alternatif
|
* Si il n'y a pas de correspondance pour ce texte, on cherche dans fichier alternatif
|
||||||
* et si toujours pas trouve, il est retourne tel quel.
|
* et si toujours pas trouve, il est retourne tel quel.
|
||||||
* Parameters of this method must not contains any HTML tags.
|
* Parameters of this method must not contains any HTML tags.
|
||||||
* \param key key of string to translate
|
* @param key key of string to translate
|
||||||
* \param param1 chaine de param1
|
* @param param1 chaine de param1
|
||||||
* \param param2 chaine de param2
|
* @param param2 chaine de param2
|
||||||
* \param param3 chaine de param3
|
* @param param3 chaine de param3
|
||||||
* \param param4 chaine de param4
|
* @param param4 chaine de param4
|
||||||
* \return string chaine traduite
|
* @return string chaine traduite
|
||||||
*/
|
*/
|
||||||
function transnoentities($key, $param1='', $param2='', $param3='', $param4='')
|
function transnoentities($key, $param1='', $param2='', $param3='', $param4='')
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user