[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] CVS: phpgwapi/inc class.translation_file.inc.php,1.3,
From: |
Miles Lott <address@hidden> |
Subject: |
[Phpgroupware-cvs] CVS: phpgwapi/inc class.translation_file.inc.php,1.3,1.4 |
Date: |
Sun, 19 May 2002 20:45:54 -0400 |
Update of /cvsroot/phpgroupware/phpgwapi/inc
In directory subversions:/tmp/cvs-serv13958
Modified Files:
class.translation_file.inc.php
Log Message:
Tweak to work more like the sql version (no more global lang var)
Index: class.translation_file.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/class.translation_file.inc.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** class.translation_file.inc.php 8 Mar 2002 04:10:58 -0000 1.3
--- class.translation_file.inc.php 20 May 2002 00:45:52 -0000 1.4
***************
*** 23,35 ****
/* $Id$ */
- // This should be considered experimental. It works, at the app level.
- // But, for admin and prefs it really slows things down. See the note
- // in the translate() function.
- // To use, set $GLOBALS['phpgw_info']["server"]["translation_system"] =
"file"; in
- // class.translation.inc.php
class translation
{
! var $langarray; // Currently loaded translations
! var $loaded_apps = array(); // Loaded app langs
/*!
--- 23,42 ----
/* $Id$ */
class translation
{
! var $lang; // Currently loaded translations
! var $loaded = False;
! var $all_loaded = False;
!
! function translation()
! {
!
if(isset($GLOBALS['phpgw_info']['user']['preferences']['common']['lang']) &&
!
$GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
! {
! $this->userlang =
$GLOBALS['phpgw_info']['user']['preferences']['common']['lang'];
! }
!
! $this->currentapp =
$GLOBALS['phpgw_info']['flags']['currentapp'];
! }
/*!
***************
*** 39,96 ****
@param $vars vars sent to lang function, passed to us
*/
! function translation($appname='phpgwapi',$loadlang='')
{
! global $lang;
! if($loadlang)
{
! $lang = $loadlang;
}
! $this->add_app($appname,$lang);
! }
!
! function translate($key, $vars=False)
! {
! global $lang;
! if
(address@hidden($GLOBALS['phpgw_info']['flags']['currentapp'],$this->loaded_apps)
&&
! $GLOBALS['phpgw_info']['flags']['currentapp']
!= 'home')
{
! //echo '<br>loading app "' .
$GLOBALS['phpgw_info']['flags']['currentapp'] . '" for the first time.';
!
$this->add_app($GLOBALS['phpgw_info']['flags']['currentapp'],$lang);
}
! elseif ($GLOBALS['phpgw_info']['flags']['currentapp']
== 'admin' ||
! $GLOBALS['phpgw_info']['flags']['currentapp']
== 'preferences')
! {
! // This is done because for these two apps, all
langs must be loaded.
! // Note we cannot load for navbar, since it
would slow down EVERY page.
! // This is true until all common/admin/prefs
langs are in the api file only.
! @ksort($GLOBALS['phpgw_info']['apps']);
! while(list($x,$app) =
each($GLOBALS['phpgw_info']['apps']))
! {
! if
(address@hidden($app['name'],$this->loaded_apps))
! {
! //echo '<br>loading app "' .
$app['name'] . '" for the first time.';
!
$this->add_app($app['name'],$lang);
! }
! }
! }
!
! if (!$vars)
{
! $vars = array();
}
! $ret = $key;
- if (isset($this->langarray[strtolower ($key)]) &&
$this->langarray[strtolower ($key)])
- {
- $ret = $this->langarray[strtolower ($key)];
- }
- else
- {
- $ret = $key."*";
- }
$ndx = 1;
! while( list($key,$val) = each( $vars ) )
{
$ret = preg_replace( "/%$ndx/", $val, $ret );
--- 46,74 ----
@param $vars vars sent to lang function, passed to us
*/
! function translate($key,$vars=False)
{
! if(!$vars)
{
! $vars = array();
}
! $ret = $key;
! $_key = strtolower($key);
! if(address@hidden($this->lang[$_key]) && !$this->loaded)
{
! $this->load_langs();
}
! if(address@hidden($this->lang[$_key]) &&
! ($this->currentapp == 'admin' ||
$this->currentapp == 'preferences') &&
! !$this->all_loaded
! )
{
! $this->load_langs(True);
}
! $ret = @isset($this->lang[$_key]) ? $this->lang[$_key]
: $key . '*';
$ndx = 1;
! while(list($key,$val) = each($vars))
{
$ret = preg_replace( "/%$ndx/", $val, $ret );
***************
*** 100,149 ****
}
! /*!
! @function add_app
! @abstract loads all app phrases into langarray
! @param $lang user lang variable (defaults to en)
! */
! function add_app($app,$lang='')
{
! define('SEP',filesystem_separator());
!
! //echo '<br>add_app(): called with app="' . $app . '",
lang="' . $userlang . '"';
! if (!isset($lang) || !$lang)
{
! if
(isset($GLOBALS['phpgw_info']['user']['preferences']['common']['lang']) &&
!
$GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
{
! $userlang =
$GLOBALS['phpgw_info']['user']['preferences']['common']['lang'];
! }
! else
! {
! $userlang = 'en';
}
}
else
{
! $userlang = $lang;
}
$fn = PHPGW_SERVER_ROOT . SEP . $app . SEP . 'setup' .
SEP . 'phpgw_' . $userlang . '.lang';
! if (!file_exists($fn))
{
$fn = PHPGW_SERVER_ROOT . SEP . $app . SEP .
'setup' . SEP . 'phpgw_en.lang';
}
! if (file_exists($fn))
{
! $fp = fopen($fn,'r');
! while ($data = fgets($fp,8000))
{
list($message_id,$app_name,$null,$content) = explode("\t",$data);
! //echo '<br>add_app(): adding phrase:
$this->langarray["'.$message_id.'"]=' . trim($content);
! $this->langarray[$message_id] =
trim($content);
}
fclose($fp);
}
- // stuff class array listing apps that are included
already
- $this->loaded_apps[] = $app;
}
}
--- 78,130 ----
}
! function load_langs($all=False)
{
! if($all)
{
! @reset($GLOBALS['phpgw_info']['user']['apps']);
! while(list(,$appname) =
@each($GLOBALS['phpgw_info']['user']['apps']))
{
! $this->add_app($appname['name']);
}
+ $this->all_loaded = True;
}
else
{
! $this->add_app('phpgwapi');
! $this->add_app($this->currentapp);
}
+ $this->loaded = True;
+ }
+
+ /*!
+ @function add_app
+ @abstract loads all app phrases into lang
+ @param $lang user lang variable (defaults to en)
+ */
+ function add_app($app)
+ {
+ //echo '<br>add_app(): adding phrases from: ' . $app;
+ define('SEP',filesystem_separator());
+
+ $userlang = $this->userlang ? $this->userlang : 'en';
+
$fn = PHPGW_SERVER_ROOT . SEP . $app . SEP . 'setup' .
SEP . 'phpgw_' . $userlang . '.lang';
! if(!file_exists($fn))
{
$fn = PHPGW_SERVER_ROOT . SEP . $app . SEP .
'setup' . SEP . 'phpgw_en.lang';
}
! if(file_exists($fn))
{
! $fp = fopen($fn,'rb');
! while($data = fgets($fp,8000))
{
list($message_id,$app_name,$null,$content) = explode("\t",$data);
! //echo '<br>add_app(): adding phrase:
$this->lang["'.$message_id.'"]=' . trim($content);
! $this->lang[$message_id] =
trim($content);
}
fclose($fp);
}
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] CVS: phpgwapi/inc class.translation_file.inc.php,1.3,1.4,
Miles Lott <address@hidden> <=