2002-03-03 22:47:30 +01:00
|
|
|
<?php
|
2006-05-29 04:56:16 +02:00
|
|
|
/**
|
2010-03-16 17:19:33 +01:00
|
|
|
* Setup translation class
|
2006-05-29 04:56:16 +02:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
2009-04-20 13:59:39 +02:00
|
|
|
if (!defined('MAX_MESSAGE_ID_LENGTH'))
|
|
|
|
{
|
|
|
|
define('MAX_MESSAGE_ID_LENGTH',128);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Define prefix for langfiles (historically 'phpgw_')
|
|
|
|
define('EGW_LANGFILE_PREFIX', 'egw_');
|
|
|
|
|
2010-03-16 17:19:33 +01:00
|
|
|
/**
|
|
|
|
* Setup translation class
|
|
|
|
*
|
|
|
|
*/
|
2009-04-20 13:59:39 +02:00
|
|
|
class setup_translation
|
|
|
|
{
|
|
|
|
var $langarray = array();
|
2003-04-02 19:46:37 +02:00
|
|
|
|
2010-03-16 17:19:33 +01:00
|
|
|
/**
|
|
|
|
* Marker to show behind untranslated phrases, default none
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $no_translation_marker = '';//'*';
|
2007-10-14 18:13:50 +02:00
|
|
|
|
2009-04-20 13:59:39 +02:00
|
|
|
/**
|
|
|
|
* constructor for the class, loads all phrases into langarray
|
|
|
|
*
|
|
|
|
* @param $lang user lang variable (defaults to en)
|
|
|
|
*/
|
|
|
|
function __construct()
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
2010-02-13 04:41:51 +01:00
|
|
|
$ConfigLang = setup::get_lang();
|
2002-03-03 22:47:30 +01:00
|
|
|
|
2009-04-20 13:59:39 +02:00
|
|
|
if(!$ConfigLang)
|
|
|
|
{
|
|
|
|
$lang = 'en';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$lang = $ConfigLang;
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
2003-10-05 04:06:11 +02:00
|
|
|
|
2009-04-20 13:59:39 +02:00
|
|
|
$fn = '.' . SEP . 'lang' . SEP . EGW_LANGFILE_PREFIX . $lang . '.lang';
|
|
|
|
if (!file_exists($fn))
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
2009-04-20 13:59:39 +02:00
|
|
|
$fn = '.' . SEP . 'lang' . SEP . EGW_LANGFILE_PREFIX .'en.lang';
|
|
|
|
}
|
|
|
|
if (file_exists($fn) && ($fp = fopen($fn,'r')))
|
|
|
|
{
|
|
|
|
while (($data = fgets($fp,8000)))
|
2005-11-27 08:48:22 +01:00
|
|
|
{
|
2009-04-20 13:59:39 +02:00
|
|
|
// explode with "\t" and removing "\n" with str_replace, needed to work with mbstring.overload=7
|
|
|
|
list($message_id,,,$content) = explode("\t",$data);
|
|
|
|
$this->langarray[strtolower(trim($message_id))] = str_replace("\n",'',$content);
|
2005-11-27 08:48:22 +01:00
|
|
|
}
|
2009-04-20 13:59:39 +02:00
|
|
|
fclose($fp);
|
|
|
|
|
|
|
|
if (!$GLOBALS['egw_setup']->system_charset)
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
2009-04-20 13:59:39 +02:00
|
|
|
$GLOBALS['egw_setup']->system_charset = $this->langarray['charset'];
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
}
|
2009-04-20 13:59:39 +02:00
|
|
|
}
|
2002-03-03 22:47:30 +01:00
|
|
|
|
2009-04-20 13:59:39 +02:00
|
|
|
/**
|
|
|
|
* Translate phrase to user selected lang
|
|
|
|
*
|
|
|
|
* @param $key phrase to translate
|
|
|
|
* @param $vars vars sent to lang function, passed to us
|
|
|
|
*/
|
|
|
|
function translate($key, $vars=False)
|
|
|
|
{
|
|
|
|
static $placeholders = array('%1','%2','%3','%4','%5','%6','%7','%8','%9','%10');
|
2002-03-03 22:47:30 +01:00
|
|
|
|
2009-04-20 13:59:39 +02:00
|
|
|
$ret = $key . $this->no_translation_marker;
|
|
|
|
$key = strtolower(trim($key));
|
|
|
|
if (isset($this->langarray[$key]))
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
2009-04-20 13:59:39 +02:00
|
|
|
$ret = $this->langarray[$key];
|
2003-10-05 04:06:11 +02:00
|
|
|
}
|
2009-04-20 13:59:39 +02:00
|
|
|
if ($GLOBALS['egw_setup']->system_charset != $this->langarray['charset'])
|
2003-10-05 04:06:11 +02:00
|
|
|
{
|
2009-04-20 13:59:39 +02:00
|
|
|
$ret = translation::convert($ret,$this->langarray['charset']);
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
2009-04-20 13:59:39 +02:00
|
|
|
if (is_array($vars))
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
2009-04-20 13:59:39 +02:00
|
|
|
$ret = str_replace($placeholders, $vars, $ret);
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
2009-04-20 13:59:39 +02:00
|
|
|
return $ret;
|
|
|
|
}
|
2002-03-03 22:47:30 +01:00
|
|
|
|
2009-04-20 13:59:39 +02:00
|
|
|
function get_langs($DEBUG=False)
|
|
|
|
{
|
|
|
|
return translaton::get_langs($DEBUG);
|
|
|
|
}
|
|
|
|
|
|
|
|
function drop_langs($appname,$DEBUG=False)
|
|
|
|
{
|
|
|
|
return translaton::drop_langs($appname,$DEBUG);
|
|
|
|
}
|
|
|
|
|
|
|
|
function add_langs($appname,$DEBUG=False,$force_langs=False)
|
|
|
|
{
|
|
|
|
return translaton::add_langs($appname,$DEBUG,$force_langs);
|
|
|
|
}
|
|
|
|
|
|
|
|
function drop_add_all_langs($langs=False)
|
|
|
|
{
|
|
|
|
if (!$langs && !count($langs = translation::get_langs()))
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
2009-04-20 13:59:39 +02:00
|
|
|
$langs[] = 'en';
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
2009-04-20 13:59:39 +02:00
|
|
|
return translation::install_langs($langs,'dumpold');
|
|
|
|
}
|
2004-10-23 17:00:44 +02:00
|
|
|
|
2009-04-20 13:59:39 +02: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')))
|
2004-11-21 10:44:02 +01:00
|
|
|
{
|
2009-04-20 13:59:39 +02:00
|
|
|
while(($line = fgets($f)) !== false)
|
2004-11-21 10:44:02 +01:00
|
|
|
{
|
2009-04-20 13:59:39 +02:00
|
|
|
list($lang,$language) = explode("\t",trim($line));
|
|
|
|
if ($lang && ($lf = @fopen("../phpgwapi/setup/" . EGW_LANGFILE_PREFIX . "$lang.lang",'r')))
|
2004-11-21 10:44:02 +01:00
|
|
|
{
|
2009-04-20 13:59:39 +02:00
|
|
|
while(($line = fgets($lf)) !== false)
|
2004-11-21 10:44:02 +01:00
|
|
|
{
|
2009-04-20 13:59:39 +02:00
|
|
|
list($phrase,,,$charset) = explode("\t",$line);
|
|
|
|
if ($phrase == 'charset')
|
2004-11-21 10:44:02 +01:00
|
|
|
{
|
2009-04-20 13:59:39 +02:00
|
|
|
$charset = trim(strtolower($charset));
|
|
|
|
|
|
|
|
if ($charset != 'utf-8')
|
2004-11-21 10:44:02 +01:00
|
|
|
{
|
2009-04-20 13:59:39 +02:00
|
|
|
$charsets[$charset] .= (isset($charsets[$charset]) ? ', ' : $charset.': ') . $language;
|
2004-11-21 10:44:02 +01:00
|
|
|
}
|
2009-04-20 13:59:39 +02:00
|
|
|
break;
|
2004-11-21 10:44:02 +01:00
|
|
|
}
|
|
|
|
}
|
2009-04-20 13:59:39 +02:00
|
|
|
fclose($lf);
|
2004-11-21 10:44:02 +01:00
|
|
|
}
|
|
|
|
}
|
2009-04-20 13:59:39 +02:00
|
|
|
fclose($f);
|
|
|
|
}
|
|
|
|
if (!$name)
|
|
|
|
{
|
|
|
|
return $charsets;
|
|
|
|
}
|
|
|
|
return html::select($name,trim(strtolower($selected)),$charsets,true);
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
2009-04-20 13:59:39 +02:00
|
|
|
}
|