phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] CVS: phpgwapi/inc class.translation_sql.inc.php,1.10,


From: Miles Lott <address@hidden>
Subject: [Phpgroupware-cvs] CVS: phpgwapi/inc class.translation_sql.inc.php,1.10,1.11
Date: Tue, 19 Feb 2002 23:30:22 -0500

Update of /cvsroot/phpgroupware/phpgwapi/inc
In directory subversions:/tmp/cvs-serv25789

Modified Files:
        class.translation_sql.inc.php 
Log Message:
Switch to using class var for $lang; translate function now does only this, and
the constructor is used to load the lang array;  I think this is faster in one 
place,
slower in another;



Index: class.translation_sql.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/class.translation_sql.inc.php,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** class.translation_sql.inc.php       17 Feb 2002 19:31:49 -0000      1.10
--- class.translation_sql.inc.php       20 Feb 2002 04:30:19 -0000      1.11
***************
*** 4,8 ****
    * This file written by Joseph Engo <address@hidden>                *
    * and Dan Kuykendall <address@hidden>                             *
!   * Handles multi-language support use SQL tables                            *
    * Copyright (C) 2000, 2001 Joseph Engo                                     *
    * -------------------------------------------------------------------------*
--- 4,9 ----
    * This file written by Joseph Engo <address@hidden>                *
    * and Dan Kuykendall <address@hidden>                             *
!   * and Miles Lott <address@hidden>                                *
!   * Handles multi-language support using SQL                                 *
    * Copyright (C) 2000, 2001 Joseph Engo                                     *
    * -------------------------------------------------------------------------*
***************
*** 27,83 ****
        class translation
        {
!               function translate($key, $vars=False) 
                {
!                       if(!$vars)
                        {
!                               $vars = array();
                        }
!                       $ret = $key;
!                       /*
!                        Check also if $GLOBALS['lang'] is a array.
!                        php-nuke and postnuke are using $GLOBALS['lang'], too,
!                        as string.
!                        This makes many problems.
!                       */
  
!                       if(isset($GLOBALS['lang'][strtolower($key)]) && 
$GLOBALS['lang'][strtolower($key)])
                        {
!                               $ret = $GLOBALS['lang'][strtolower($key)];
                        }
!                       elseif(!isset($GLOBALS['lang']) || !$GLOBALS['lang'] || 
!is_array($GLOBALS['lang']))
                        {
!                               $GLOBALS['lang'] = array();
!                               
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';
!                               }
!                               $sql = "SELECT message_id,content FROM 
phpgw_lang WHERE lang LIKE '" . $userlang
!                                       . "' AND (app_name LIKE '" . 
$GLOBALS['phpgw_info']['flags']['currentapp']
!                                       . "' OR app_name LIKE 'common' OR 
app_name LIKE 'all')";
! 
!                               if (strcasecmp 
($GLOBALS['phpgw_info']['flags']['currentapp'], 'common')>0)
!                               {
!                                       $sql .= ' ORDER BY app_name ASC';
!                               }
!                               else
!                               {
!                                       $sql .= ' ORDER BY app_name DESC';
!                               }
  
!                               
$GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
                                $GLOBALS['phpgw']->db->next_record();
-                               $count = $GLOBALS['phpgw']->db->num_rows();
-                               for($idx = 0; $idx < $count; ++$idx)
-                               {
-                                       
$GLOBALS['lang'][strtolower($GLOBALS['phpgw']->db->f('message_id'))] = 
$GLOBALS['phpgw']->db->f('content');
-                                       $GLOBALS['phpgw']->db->next_record();
-                               }
-                               $ret = $GLOBALS['lang'][strtolower($key)] ? 
$GLOBALS['lang'][strtolower($key)] : $key . '*';
                        }
  
                        $ndx = 1;
--- 28,97 ----
        class translation
        {
!               var $lang = array();
!               var $userlang   = '';
!               var $currentapp = '';
! 
!               /*!
!                @function translation
!                @abstract class constructor - loads up translations into 
$this->lang based on currentapp and userlang preference, if present.
!                @discussion This also loads translations with appname='common' 
or appname='all'.  User lang defaults to 'en'.
!               */
!               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'];
                        }
!                       else
!                       {
!                               $this->userlang = 'en';
!                       }
! 
!                       $this->currentapp = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
  
!                       $sql = "SELECT message_id,content FROM phpgw_lang WHERE 
lang LIKE '" . $this->userlang
!                               . "' AND (app_name LIKE '" . $this->currentapp
!                               . "' OR app_name LIKE 'common' OR app_name LIKE 
'all') ORDER BY app_name ";
! 
!                       if(strcasecmp($this->currentapp, 'common') > 0)
                        {
!                               $sql .= 'ASC';
                        }
!                       else
                        {
!                               $sql .= 'DESC';
!                       }
  
!                       $GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
!                       $GLOBALS['phpgw']->db->next_record();
! 
!                       $count = $GLOBALS['phpgw']->db->num_rows();
!                       for($idx = 0; $idx < $count; ++$idx)
!                       {
!                               
$this->lang[strtolower($GLOBALS['phpgw']->db->f('message_id'))] = 
$GLOBALS['phpgw']->db->f('content');
                                $GLOBALS['phpgw']->db->next_record();
                        }
+                       /* Done stuffing the array.  If someone prefers to have 
$GLOBALS['lang'] set to this as before,
+                          it could be done here. - $GLOBALS['lang'] = 
$this->lang;
+                       */
+               }
+ 
+               /*!
+                @function translate
+                @abstract Return the translated string from $this->lang, if it 
exists.  If no translation exists, return the same string with an asterisk.
+                @discussion This should be called from the global function 
lang(), not directly.
+                @syntax translate('translate this x', $somevar);
+               */
+               function translate($key,$vars=False) 
+               {
+                       if(!$vars)
+                       {
+                               $vars = array();
+                       }
+                       $ret  = $key;
+                       $_key = strtolower($key);
+ 
+                       $ret = $this->lang[$_key] ? $this->lang[$_key] : $key . 
'*';
  
                        $ndx = 1;
***************
*** 90,120 ****
                }
  
                function add_app($app) 
                {
!                       /*
!                        post-nuke and php-nuke are using $GLOBALS['lang'], too.
!                        But not as array!
!                        This produces very strange results.
!                       */
!                       if(!is_array($GLOBALS['lang']))
!                       {
!                               $GLOBALS['lang'] = array();
!                       }
!                       
!                       
if($GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
!                       {
!                               $userlang = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['lang'];
!                       }
!                       else
!                       {
!                               $userlang = 'en';
!                       }
!                       $sql = "SELECT message_id,content FROM phpgw_lang WHERE 
lang LIKE '".$userlang."' AND app_name LIKE '".$app."'";
                        $GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
                        $GLOBALS['phpgw']->db->next_record();
                        $count = $GLOBALS['phpgw']->db->num_rows();
                        for($idx = 0; $idx < $count; ++$idx)
                        {
!                               $GLOBALS['lang'][strtolower 
($GLOBALS['phpgw']->db->f('message_id'))] = $GLOBALS['phpgw']->db->f('content');
                                $GLOBALS['phpgw']->db->next_record();
                        }
--- 104,123 ----
                }
  
+               /*!
+                @function add_app
+                @abstract Add an additional app's translations to $this->lang
+               */
                function add_app($app) 
                {
!                       $sql = "SELECT message_id,content FROM phpgw_lang WHERE 
lang LIKE '" . $this->userlang
!                               . "' AND app_name LIKE '" . $app . "'";
! 
                        $GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
                        $GLOBALS['phpgw']->db->next_record();
+ 
                        $count = $GLOBALS['phpgw']->db->num_rows();
                        for($idx = 0; $idx < $count; ++$idx)
                        {
!                               
$this->lang[strtolower($GLOBALS['phpgw']->db->f('message_id'))] = 
$GLOBALS['phpgw']->db->f('content');
                                $GLOBALS['phpgw']->db->next_record();
                        }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]