[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare API - Translation class for phpgw lang files * 4 * This file written by Miles Lott <milosch@groupwhere.org> * 5 * and Dan Kuykendall <seek3r@phpgroupware.org> * 6 * Handles multi-language support using flat files * 7 * -------------------------------------------------------------------------* 8 * This library is part of the eGroupWare API * 9 * http://www.egroupware.org/api * 10 * ------------------------------------------------------------------------ * 11 * This library is free software; you can redistribute it and/or modify it * 12 * under the terms of the GNU Lesser General Public License as published by * 13 * the Free Software Foundation; either version 2.1 of the License, * 14 * or any later version. * 15 * This library is distributed in the hope that it will be useful, but * 16 * WITHOUT ANY WARRANTY; without even the implied warranty of * 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 18 * See the GNU Lesser General Public License for more details. * 19 * You should have received a copy of the GNU Lesser General Public License * 20 * along with this library; if not, write to the Free Software Foundation, * 21 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 22 \**************************************************************************/ 23 24 /* $Id: class.setup_translation.inc.php 20018 2005-11-27 07:48:22Z ralfbecker $ */ 25 26 if (!defined('MAX_MESSAGE_ID_LENGTH')) 27 { 28 define('MAX_MESSAGE_ID_LENGTH',128); 29 } 30 31 class setup_translation 32 { 33 var $langarray = array(); 34 35 /** 36 * constructor for the class, loads all phrases into langarray 37 * 38 * @param $lang user lang variable (defaults to en) 39 */ 40 function setup_translation() 41 { 42 $ConfigLang = get_var('ConfigLang',Array('POST','COOKIE')); 43 44 if(!$ConfigLang) 45 { 46 $lang = 'en'; 47 } 48 else 49 { 50 $lang = $ConfigLang; 51 } 52 53 $fn = '.' . SEP . 'lang' . SEP . 'phpgw_' . $lang . '.lang'; 54 if (!file_exists($fn)) 55 { 56 $fn = '.' . SEP . 'lang' . SEP . 'phpgw_en.lang'; 57 } 58 if (file_exists($fn)) 59 { 60 $fp = fopen($fn,'r'); 61 while ($data = fgets($fp,8000)) 62 { 63 // explode with "\t" and removing "\n" with str_replace, needed to work with mbstring.overload=7 64 list($message_id,,,$content) = explode("\t",$data); 65 $this->langarray[strtolower(trim($message_id))] = str_replace("\n",'',$content); 66 } 67 fclose($fp); 68 69 if (!$GLOBALS['egw_setup']->system_charset) 70 { 71 $GLOBALS['egw_setup']->system_charset = $this->langarray['charset']; 72 } 73 } 74 } 75 76 /** 77 * Translate phrase to user selected lang 78 * 79 * @param $key phrase to translate 80 * @param $vars vars sent to lang function, passed to us 81 */ 82 function translate($key, $vars=False) 83 { 84 $ret = $key.'*'; 85 $key = strtolower(trim($key)); 86 if (isset($this->langarray[$key])) 87 { 88 $ret = $this->langarray[$key]; 89 } 90 if ($GLOBALS['egw_setup']->system_charset != $this->langarray['charset']) 91 { 92 if (!is_object($this->sql)) 93 { 94 $this->setup_translation_sql(); 95 } 96 $ret = $this->sql->convert($ret,$this->langarray['charset']); 97 } 98 if (is_array($vars)) 99 { 100 foreach($vars as $n => $var) 101 { 102 $ret = preg_replace( '/%'.($n+1).'/', $var, $ret ); 103 } 104 } 105 return $ret; 106 } 107 108 // the following functions have been moved to phpgwapi/tanslation_sql 109 110 function setup_translation_sql() 111 { 112 if (!is_object($this->sql)) 113 { 114 include_once(EGW_API_INC.'/class.translation.inc.php'); 115 $this->sql =& new translation; 116 } 117 } 118 119 function get_langs($DEBUG=False) 120 { 121 $this->setup_translation_sql(); 122 return $this->sql->get_langs($DEBUG); 123 } 124 125 function drop_langs($appname,$DEBUG=False) 126 { 127 $this->setup_translation_sql(); 128 return $this->sql->drop_langs($appname,$DEBUG); 129 } 130 131 function add_langs($appname,$DEBUG=False,$force_langs=False) 132 { 133 $this->setup_translation_sql(); 134 return $this->sql->add_langs($appname,$DEBUG,$force_langs); 135 } 136 137 function drop_add_all_langs($langs=False) 138 { 139 $this->setup_translation_sql(); 140 141 if (!$langs && !count($langs = $this->sql->get_langs())) 142 { 143 $langs[] = 'en'; 144 } 145 return $this->sql->install_langs($langs,'dumpold'); 146 } 147 148 /** 149 * List availible charsets and it's supported languages 150 * @param boolean/string $name=false name for selectbox or false to return an array 151 * @param string $selected selected charset 152 * @return string/array html for a selectbox or array with charset / languages pairs 153 */ 154 function get_charsets($name=false,$selected='') 155 { 156 $charsets = array( 157 'utf-8' => 'utf-8: '.lang('all languages (incl. not listed ones)'), 158 ); 159 if (($f = fopen('lang/languages','r'))) 160 { 161 while(($line = fgets($f)) !== false) 162 { 163 list($lang,$language) = explode("\t",trim($line)); 164 if ($lang && ($lf = @fopen("../phpgwapi/setup/phpgw_$lang.lang",'r'))) 165 { 166 while(($line = fgets($lf)) !== false) 167 { 168 list($phrase,,,$charset) = explode("\t",$line); 169 if ($phrase == 'charset') 170 { 171 $charset = trim(strtolower($charset)); 172 173 if ($charset != 'utf-8') 174 { 175 $charsets[$charset] .= (isset($charsets[$charset]) ? ', ' : $charset.': ') . $language; 176 } 177 break; 178 } 179 } 180 fclose($lf); 181 } 182 } 183 fclose($f); 184 } 185 if (!$name) 186 { 187 return $charsets; 188 } 189 $html =& CreateObject('phpgwapi.html'); 190 191 return $html->select($name,trim(strtolower($selected)),$charsets,true); 192 } 193 } 194 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |