mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-06-25 12:21:26 +02:00
speedup for the translation function
This commit is contained in:
parent
503b1d123c
commit
b4f8235976
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
class setup_translation
|
class setup_translation
|
||||||
{
|
{
|
||||||
var $langarray;
|
var $langarray = array();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@function setup_lang
|
@function setup_lang
|
||||||
@ -55,20 +55,13 @@
|
|||||||
{
|
{
|
||||||
$fn = '.' . SEP . 'lang' . SEP . 'phpgw_en.lang';
|
$fn = '.' . SEP . 'lang' . SEP . 'phpgw_en.lang';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_exists($fn))
|
if (file_exists($fn))
|
||||||
{
|
{
|
||||||
$fp = fopen($fn,'r');
|
$fp = fopen($fn,'r');
|
||||||
while ($data = fgets($fp,8000))
|
while ($data = fgets($fp,8000))
|
||||||
{
|
{
|
||||||
list($message_id,$app_name,$null,$content) = explode("\t",$data);
|
list($message_id,$app_name,$null,$content) = explode("\t",substr($data,0,-1));
|
||||||
if ($app_name == 'setup' || $app_name == 'common' || $app_name == 'all')
|
$this->langarray[strtolower(trim($message_id))] = $content;
|
||||||
{
|
|
||||||
$this->langarray[] = array(
|
|
||||||
'message_id' => $message_id,
|
|
||||||
'content' => trim($content)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
}
|
}
|
||||||
@ -82,32 +75,18 @@
|
|||||||
*/
|
*/
|
||||||
function translate($key, $vars=False)
|
function translate($key, $vars=False)
|
||||||
{
|
{
|
||||||
if (!$vars)
|
$ret = $key.'*';
|
||||||
|
$key = strtolower(trim($key));
|
||||||
|
if (isset($this->langarray[$key]))
|
||||||
{
|
{
|
||||||
$vars = array();
|
$ret = $this->langarray[$key];
|
||||||
}
|
}
|
||||||
|
if (is_array($vars))
|
||||||
$ret = $key;
|
|
||||||
|
|
||||||
@reset($this->langarray);
|
|
||||||
while(list($null,$data) = @each($this->langarray))
|
|
||||||
{
|
{
|
||||||
$lang[strtolower($data['message_id'])] = $data['content'];
|
foreach($vars as $n => $var)
|
||||||
}
|
{
|
||||||
|
$ret = preg_replace( '/%'.($n+1).'/', $var, $ret );
|
||||||
if (isset($lang[strtolower ($key)]) && $lang[strtolower ($key)])
|
}
|
||||||
{
|
|
||||||
$ret = $lang[strtolower ($key)];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$ret = $key.'*';
|
|
||||||
}
|
|
||||||
$ndx = 1;
|
|
||||||
while( list($key,$val) = each( $vars ) )
|
|
||||||
{
|
|
||||||
$ret = preg_replace( "/%$ndx/", $val, $ret );
|
|
||||||
++$ndx;
|
|
||||||
}
|
}
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user