phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] phpgwapi/inc/class.translation_sql.inc.php, 1.19


From: nomail
Subject: [Phpgroupware-cvs] phpgwapi/inc/class.translation_sql.inc.php, 1.19
Date: Thu, 30 Dec 2004 07:47:31 +0100

Update of /phpgwapi/inc
Added Files:
        Branch: 
          class.translation_sql.inc.php

date: 2004/12/30 06:47:31;  author: skwashd;  state: Exp;  lines: +89 -125

Log Message:
new HEAD
=====================================================================
<?php
        /**
        * Handles multi-language support use SQL tables
        * @author Joseph Engo <address@hidden>
        * @author Dan Kuykendall <address@hidden>
        * @copyright Portions Copyright (C) 2000-2004 Free Software Foundation, 
Inc. http://www.fsf.org/
        * @license http://www.fsf.org/licenses/lgpl.html GNU Lesser General 
Public License
        * @package phpgwapi
        * @subpackage application
        * @version $Id: class.translation_sql.inc.php,v 1.19 2004/12/30 
06:47:31 skwashd Exp $
        */

        /**
        * define the maximal length of a message_id, all message_ids have to be 
unique 
        * in this length, our column is varchar 255, but addslashes might add 
some length
        */
        define('MAX_MESSAGE_ID_LENGTH',230);    
        
        /**
        * Handles multi-language support use SQL tables
        * 
        * @package phpgwapi
        * @subpackage application
        */
        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 ( !is_array($GLOBALS['lang']) ) //This should avoid 
problems for php-nuke & postnuke I guess (Caeies)
                        {
                                $GLOBALS['lang'] = array();
                        }
                        
if(!array_key_exists(strtolower(trim(substr($key,0,MAX_MESSAGE_ID_LENGTH))),$GLOBALS['lang']))
 //Using array_key_exists permits empty string ... Ugly but ... (Caeies)
//                      if (!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 = '".$userlang."' ".
                                        "and message_id = 
'".$GLOBALS['phpgw']->db->db_addslashes($key)."' or message_id = 'charset' and 
(app_name = '".$GLOBALS['phpgw_info']['flags']['currentapp']."' or app_name = 
'common' or app_name = 'all')";
                        //              "and (app_name = 
'".$GLOBALS['phpgw_info']['flags']['currentapp']."' or app_name = 'common' or 
app_name = '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__);
        while ($GLOBALS['phpgw']->db->next_record())
        {
          
$GLOBALS['lang'][strtolower($GLOBALS['phpgw']->db->resultSet->fields('message_id'))]
 = $GLOBALS['phpgw']->db->resultSet->fields('content');
                                }
                        }
                        $ret = $key.'*';        // save key if we dont find a 
translation
                        $key = 
strtolower(trim(substr($key,0,MAX_MESSAGE_ID_LENGTH)));

                        if (isset($GLOBALS['lang'][$key]))
                        {
                                $ret = $GLOBALS['lang'][$key];
                        }
                        $ndx = 1;
                        while( list($key,$val) = each( $vars ) )
                        {
                                $ret = preg_replace( "/%$ndx/", $val, $ret );
                                ++$ndx;
                        }
                        return $ret;
                }

                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();
                        }
                }
                
                function get_installed_langs()
                {
                        $GLOBALS['phpgw']->db->query("SELECT DISTINCT 
l.lang,ln.lang_name FROM phpgw_lang l,phpgw_languages ln WHERE l.lang = 
ln.lang_id",__LINE__,__FILE__);
                        if (!$GLOBALS['phpgw']->db->num_rows())
                        {
                                return False;
                        }
                        while ($GLOBALS['phpgw']->db->next_record())
                        {
                                $langs[$GLOBALS['phpgw']->db->f('lang')] = 
$GLOBALS['phpgw']->db->f('lang_name');
                        }
                        return $langs;
                }
        }




reply via email to

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