2002-03-03 22:47:30 +01:00
|
|
|
<?php
|
2006-05-29 04:56:16 +02:00
|
|
|
/**
|
|
|
|
* Setup
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @package setup
|
|
|
|
* @author Dan Kuykendall <seek3r@phpgroupware.org>
|
|
|
|
* @author Miles Lott <milos@groupwhere.org>
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
2002-03-03 22:47:30 +01:00
|
|
|
|
2003-04-02 19:46:37 +02:00
|
|
|
if (!defined('MAX_MESSAGE_ID_LENGTH'))
|
|
|
|
{
|
2005-11-04 19:35:09 +01:00
|
|
|
define('MAX_MESSAGE_ID_LENGTH',128);
|
2003-04-02 19:46:37 +02:00
|
|
|
}
|
|
|
|
|
2007-10-14 18:13:50 +02:00
|
|
|
// Define prefix for langfiles (historically 'phpgw_')
|
|
|
|
define('EGW_LANGFILE_PREFIX', 'egw_');
|
|
|
|
|
2002-03-03 22:47:30 +01:00
|
|
|
class setup_translation
|
|
|
|
{
|
2004-03-23 17:34:23 +01:00
|
|
|
var $langarray = array();
|
2006-05-29 04:56:16 +02:00
|
|
|
|
|
|
|
var $no_translation_marker = '*';
|
2002-03-03 22:47:30 +01:00
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* constructor for the class, loads all phrases into langarray
|
|
|
|
*
|
|
|
|
* @param $lang user lang variable (defaults to en)
|
|
|
|
*/
|
2002-03-03 22:47:30 +01:00
|
|
|
function setup_translation()
|
|
|
|
{
|
2002-04-30 05:35:52 +02:00
|
|
|
$ConfigLang = get_var('ConfigLang',Array('POST','COOKIE'));
|
2002-03-03 22:47:30 +01:00
|
|
|
|
|
|
|
if(!$ConfigLang)
|
|
|
|
{
|
|
|
|
$lang = 'en';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$lang = $ConfigLang;
|
|
|
|
}
|
2005-11-27 08:48:22 +01:00
|
|
|
|
2007-10-14 18:13:50 +02:00
|
|
|
$fn = '.' . SEP . 'lang' . SEP . EGW_LANGFILE_PREFIX . $lang . '.lang';
|
2002-03-03 22:47:30 +01:00
|
|
|
if (!file_exists($fn))
|
|
|
|
{
|
2007-10-14 18:13:50 +02:00
|
|
|
$fn = '.' . SEP . 'lang' . SEP . EGW_LANGFILE_PREFIX .'en.lang';
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
if (file_exists($fn))
|
|
|
|
{
|
|
|
|
$fp = fopen($fn,'r');
|
|
|
|
while ($data = fgets($fp,8000))
|
|
|
|
{
|
2004-05-09 12:17:44 +02:00
|
|
|
// explode with "\t" and removing "\n" with str_replace, needed to work with mbstring.overload=7
|
2004-05-09 12:25:30 +02:00
|
|
|
list($message_id,,,$content) = explode("\t",$data);
|
2004-05-09 12:17:44 +02:00
|
|
|
$this->langarray[strtolower(trim($message_id))] = str_replace("\n",'',$content);
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
fclose($fp);
|
2005-11-27 08:48:22 +01:00
|
|
|
|
|
|
|
if (!$GLOBALS['egw_setup']->system_charset)
|
|
|
|
{
|
|
|
|
$GLOBALS['egw_setup']->system_charset = $this->langarray['charset'];
|
|
|
|
}
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
}
|
2003-10-05 04:06:11 +02:00
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* Translate phrase to user selected lang
|
|
|
|
*
|
|
|
|
* @param $key phrase to translate
|
|
|
|
* @param $vars vars sent to lang function, passed to us
|
|
|
|
*/
|
2002-03-03 22:47:30 +01:00
|
|
|
function translate($key, $vars=False)
|
|
|
|
{
|
2006-05-29 04:56:16 +02:00
|
|
|
$ret = $key . $this->no_translation_marker;
|
2004-03-23 17:34:23 +01:00
|
|
|
$key = strtolower(trim($key));
|
|
|
|
if (isset($this->langarray[$key]))
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
2004-03-23 17:34:23 +01:00
|
|
|
$ret = $this->langarray[$key];
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
2005-11-27 08:48:22 +01:00
|
|
|
if ($GLOBALS['egw_setup']->system_charset != $this->langarray['charset'])
|
|
|
|
{
|
|
|
|
if (!is_object($this->sql))
|
|
|
|
{
|
|
|
|
$this->setup_translation_sql();
|
|
|
|
}
|
|
|
|
$ret = $this->sql->convert($ret,$this->langarray['charset']);
|
|
|
|
}
|
2004-03-23 17:34:23 +01:00
|
|
|
if (is_array($vars))
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
2004-03-23 17:34:23 +01:00
|
|
|
foreach($vars as $n => $var)
|
|
|
|
{
|
2006-05-29 04:56:16 +02:00
|
|
|
$ret = str_replace( '%'.($n+1), $var, $ret );
|
2004-03-23 17:34:23 +01:00
|
|
|
}
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2003-10-05 04:06:11 +02:00
|
|
|
// the following functions have been moved to phpgwapi/tanslation_sql
|
2002-03-03 22:47:30 +01:00
|
|
|
|
2003-10-05 04:06:11 +02:00
|
|
|
function setup_translation_sql()
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
2006-05-31 19:21:25 +02:00
|
|
|
if (!is_object($this->sql) || is_object($GLOBALS['egw_setup']->db) && !is_object($this->sql->db))
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
2005-11-05 13:50:55 +01:00
|
|
|
include_once(EGW_API_INC.'/class.translation.inc.php');
|
2005-03-24 14:15:12 +01:00
|
|
|
$this->sql =& new translation;
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
2003-10-05 04:06:11 +02:00
|
|
|
}
|
2002-03-03 22:47:30 +01:00
|
|
|
|
2003-10-05 04:06:11 +02:00
|
|
|
function get_langs($DEBUG=False)
|
|
|
|
{
|
|
|
|
$this->setup_translation_sql();
|
|
|
|
return $this->sql->get_langs($DEBUG);
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function drop_langs($appname,$DEBUG=False)
|
|
|
|
{
|
2003-10-05 04:06:11 +02:00
|
|
|
$this->setup_translation_sql();
|
|
|
|
return $this->sql->drop_langs($appname,$DEBUG);
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
|
2003-10-04 15:24:34 +02:00
|
|
|
function add_langs($appname,$DEBUG=False,$force_langs=False)
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
2003-10-05 04:06:11 +02:00
|
|
|
$this->setup_translation_sql();
|
|
|
|
return $this->sql->add_langs($appname,$DEBUG,$force_langs);
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
2004-10-23 17:00:44 +02:00
|
|
|
|
|
|
|
function drop_add_all_langs($langs=False)
|
|
|
|
{
|
|
|
|
$this->setup_translation_sql();
|
|
|
|
|
|
|
|
if (!$langs && !count($langs = $this->sql->get_langs()))
|
|
|
|
{
|
|
|
|
$langs[] = 'en';
|
|
|
|
}
|
|
|
|
return $this->sql->install_langs($langs,'dumpold');
|
|
|
|
}
|
2004-11-21 10:44:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List availible charsets and it's supported languages
|
|
|
|
* @param boolean/string $name=false name for selectbox or false to return an array
|
|
|
|
* @param string $selected selected charset
|
|
|
|
* @return string/array html for a selectbox or array with charset / languages pairs
|
|
|
|
*/
|
|
|
|
function get_charsets($name=false,$selected='')
|
|
|
|
{
|
|
|
|
$charsets = array(
|
|
|
|
'utf-8' => 'utf-8: '.lang('all languages (incl. not listed ones)'),
|
|
|
|
);
|
|
|
|
if (($f = fopen('lang/languages','r')))
|
|
|
|
{
|
|
|
|
while(($line = fgets($f)) !== false)
|
|
|
|
{
|
|
|
|
list($lang,$language) = explode("\t",trim($line));
|
2007-10-14 18:13:50 +02:00
|
|
|
if ($lang && ($lf = @fopen("../phpgwapi/setup/" . EGW_LANGFILE_PREFIX . "$lang.lang",'r')))
|
2004-11-21 10:44:02 +01:00
|
|
|
{
|
|
|
|
while(($line = fgets($lf)) !== false)
|
|
|
|
{
|
|
|
|
list($phrase,,,$charset) = explode("\t",$line);
|
|
|
|
if ($phrase == 'charset')
|
|
|
|
{
|
|
|
|
$charset = trim(strtolower($charset));
|
|
|
|
|
|
|
|
if ($charset != 'utf-8')
|
|
|
|
{
|
|
|
|
$charsets[$charset] .= (isset($charsets[$charset]) ? ', ' : $charset.': ') . $language;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose($lf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose($f);
|
|
|
|
}
|
|
|
|
if (!$name)
|
|
|
|
{
|
|
|
|
return $charsets;
|
|
|
|
}
|
2005-03-24 14:15:12 +01:00
|
|
|
$html =& CreateObject('phpgwapi.html');
|
2004-11-21 10:44:02 +01:00
|
|
|
|
2004-12-05 17:35:24 +01:00
|
|
|
return $html->select($name,trim(strtolower($selected)),$charsets,true);
|
2004-11-21 10:44:02 +01:00
|
|
|
}
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
?>
|