2001-01-11 10:52:33 +01:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2001-01-13 11:18:50 +01:00
|
|
|
* phpGroupWare API - Translation class for SQL *
|
|
|
|
* This file written by Joseph Engo <jengo@phpgroupware.org> *
|
|
|
|
* and Dan Kuykendall <seek3r@phpgroupware.org> *
|
2003-08-28 16:31:11 +02:00
|
|
|
* Handles multi-language support use SQL tables *
|
2001-01-13 11:18:50 +01:00
|
|
|
* Copyright (C) 2000, 2001 Joseph Engo *
|
|
|
|
* -------------------------------------------------------------------------*
|
2001-01-16 14:52:32 +01:00
|
|
|
* This library is part of the phpGroupWare API *
|
|
|
|
* http://www.phpgroupware.org/api *
|
|
|
|
* ------------------------------------------------------------------------ *
|
2001-01-13 11:18:50 +01:00
|
|
|
* This library is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2.1 of the License, *
|
|
|
|
* or any later version. *
|
|
|
|
* This library is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
|
|
* See the GNU Lesser General Public License for more details. *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
* along with this library; if not, write to the Free Software Foundation, *
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
2001-01-11 10:52:33 +01:00
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
2003-04-02 19:46:37 +02:00
|
|
|
// 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
|
2003-08-28 16:31:11 +02:00
|
|
|
define('MAX_MESSAGE_ID_LENGTH',230);
|
|
|
|
|
2001-06-15 23:29:33 +02:00
|
|
|
class translation
|
|
|
|
{
|
2003-09-14 12:20:46 +02:00
|
|
|
var $userlang = 'en';
|
|
|
|
var $loaded_apps = array();
|
|
|
|
|
|
|
|
function init()
|
|
|
|
{
|
|
|
|
// 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'])
|
|
|
|
{
|
|
|
|
$this->userlang = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'];
|
|
|
|
}
|
|
|
|
$this->add_app('common');
|
|
|
|
$this->add_app($GLOBALS['phpgw_info']['flags']['currentapp']);
|
|
|
|
}
|
|
|
|
|
|
|
|
function translate($key, $vars=false )
|
2002-02-20 05:44:19 +01:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
if (!$vars)
|
2002-10-19 00:53:12 +02:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$vars = array();
|
2002-02-17 19:43:31 +01:00
|
|
|
}
|
2003-09-14 12:20:46 +02:00
|
|
|
if (!is_array($GLOBALS['lang']) || !count($GLOBALS['lang']))
|
2001-06-15 23:29:33 +02:00
|
|
|
{
|
2003-09-14 12:20:46 +02:00
|
|
|
$this->init();
|
2001-06-15 23:29:33 +02:00
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
$ret = $key.'*'; // save key if we dont find a translation
|
2003-09-14 12:20:46 +02:00
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
$key = strtolower(trim(substr($key,0,MAX_MESSAGE_ID_LENGTH)));
|
2002-02-20 05:30:19 +01:00
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
if (isset($GLOBALS['lang'][$key]))
|
2002-02-20 05:44:19 +01:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$ret = $GLOBALS['lang'][$key];
|
2002-02-20 05:44:19 +01:00
|
|
|
}
|
2001-06-15 23:29:33 +02:00
|
|
|
$ndx = 1;
|
2003-09-14 12:20:46 +02:00
|
|
|
foreach($vars as $val)
|
2001-06-15 23:29:33 +02:00
|
|
|
{
|
|
|
|
$ret = preg_replace( "/%$ndx/", $val, $ret );
|
|
|
|
++$ndx;
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2003-09-15 10:42:47 +02:00
|
|
|
function add_app($app,$lang=False)
|
2001-06-15 23:29:33 +02:00
|
|
|
{
|
2003-09-15 10:42:47 +02:00
|
|
|
$lang = $lang ? $lang : $this->userlang;
|
|
|
|
|
|
|
|
if (!isset($this->loaded_apps[$app]) || $this->loaded_apps[$app] != $lang)
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2003-09-15 10:42:47 +02:00
|
|
|
$sql = "select message_id,content from phpgw_lang where lang='".$lang."' and app_name='".$app."'";
|
2003-09-14 12:20:46 +02:00
|
|
|
$GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
|
|
|
|
while ($GLOBALS['phpgw']->db->next_record())
|
|
|
|
{
|
|
|
|
$GLOBALS['lang'][strtolower ($GLOBALS['phpgw']->db->f('message_id'))] = $GLOBALS['phpgw']->db->f('content');
|
|
|
|
}
|
2003-09-15 10:42:47 +02:00
|
|
|
$this->loaded_apps[$app] = $lang;
|
2001-06-15 23:29:33 +02:00
|
|
|
}
|
|
|
|
}
|
2003-09-14 12:20:46 +02:00
|
|
|
|
2003-04-02 19:46:37 +02:00
|
|
|
function get_installed_langs()
|
|
|
|
{
|
2003-09-14 12:20:46 +02:00
|
|
|
if (!is_array($this->langs))
|
2003-04-02 19:46:37 +02:00
|
|
|
{
|
2003-09-14 12:20:46 +02:00
|
|
|
$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())
|
|
|
|
{
|
|
|
|
$this->langs[$GLOBALS['phpgw']->db->f('lang')] = $GLOBALS['phpgw']->db->f('lang_name');
|
|
|
|
}
|
2003-04-02 19:46:37 +02:00
|
|
|
}
|
2003-09-14 12:20:46 +02:00
|
|
|
return $this->langs;
|
2003-04-02 19:46:37 +02:00
|
|
|
}
|
2001-06-15 23:29:33 +02:00
|
|
|
}
|