| 3 |
// $Id$ |
// $Id$ |
| 4 |
// ------------------------------------------------------------------ |
// ------------------------------------------------------------------ |
| 5 |
// $Log$ |
// $Log$ |
| 6 |
|
// Revision 1.7 2003/05/13 09:40:34 joko |
| 7 |
|
// check for error... |
| 8 |
|
// |
| 9 |
|
// Revision 1.6 2003/02/09 17:33:54 joko |
| 10 |
|
// + minor update related to new log level constants |
| 11 |
|
// |
| 12 |
|
// Revision 1.5 2002/12/19 10:30:06 joko |
| 13 |
|
// + argument 'newMode' for function getlt and function _getldsvar: let _getldsvar evaluate variable to still provide old behaviour/functionality |
| 14 |
|
// |
| 15 |
|
// Revision 1.4 2002/12/19 06:18:40 joko |
| 16 |
|
// + '$this->site' gets used here now |
| 17 |
|
// |
| 18 |
// Revision 1.3 2002/12/04 07:40:05 jonen |
// Revision 1.3 2002/12/04 07:40:05 jonen |
| 19 |
// + comment out dprint |
// + comment out dprint |
| 20 |
// |
// |
| 64 |
|
|
| 65 |
// ---------------------------------------------------- |
// ---------------------------------------------------- |
| 66 |
function LocaleText() { |
function LocaleText() { |
| 67 |
global $cfg, $slt; |
|
| 68 |
|
// look at the bottom of this file!!! |
| 69 |
|
//$smarty->register_block("translate", "do_translation"); |
| 70 |
|
//$this->site->smarty->register_block("translate", "_do_translation"); |
| 71 |
|
|
| 72 |
|
//global $site; |
| 73 |
|
//$site->smarty->register_block("translate", "_do_translation"); |
| 74 |
|
|
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
function start() { |
| 78 |
|
global $app, $slt; |
| 79 |
session_register_safe('slt'); |
session_register_safe('slt'); |
| 80 |
$this->langs_avail = $cfg[GLBL_LANGSAVAIL]; |
$this->langs_avail = $app->getConfig("languages.available"); |
| 81 |
$this->load(); |
$this->load(); |
| 82 |
} |
} |
| 83 |
|
|
| 111 |
return $langs_avail[0]; |
return $langs_avail[0]; |
| 112 |
} |
} |
| 113 |
} |
} |
| 114 |
|
|
| 115 |
|
// TODO: refactor this to Data::Deep |
| 116 |
function _dbkey2ldskey($dbkey) { |
function _dbkey2ldskey($dbkey) { |
| 117 |
// TODO: log this |
// TODO: log this |
| 118 |
//dprint("dbkey: $dbkey"); |
//dprint("dbkey: $dbkey"); |
| 126 |
} |
} |
| 127 |
} |
} |
| 128 |
|
|
| 129 |
function _getldsvar($ldskey, $tpl=array()) { |
// TODO: refactor this to Data::Deep |
| 130 |
|
function _getldsvar($ldskey, $tpl=array(), $newMode = 0) { |
| 131 |
|
|
| 132 |
|
//print "ldskey: $ldskey<br>"; |
| 133 |
|
|
| 134 |
$var_name = '$this->lds' . $ldskey; |
$var_name = '$this->lds' . $ldskey; |
| 135 |
$eval_string = "return $var_name;"; |
$eval_string = "return $var_name;"; |
| 136 |
//print $eval_string . "<br>"; |
//print $eval_string . "<br>"; |
| 137 |
|
|
| 138 |
// interpolate variable-name |
// interpolate variable-name |
| 139 |
$var_value = eval($eval_string); |
$var_value = eval($eval_string); |
| 140 |
// interpolate variable-value to do some template-vars |
// interpolate variable-value to do some template-vars |
| 141 |
$var_value = eval("return \"$var_value\";"); |
if (!$newMode) { |
| 142 |
|
$var_value = eval("return \"$var_value\";"); |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
// V1 - result interpolation using eval |
| 146 |
// print $eval_string."<br>"; |
// print $eval_string."<br>"; |
| 147 |
//$var_value = $$var_name; |
//$var_value = $$var_name; |
| 148 |
|
|
| 149 |
|
// V2 - result interpolation using smarty |
| 150 |
|
//print Dumper($tpl); |
| 151 |
|
//$this->site->loadTemplate(); |
| 152 |
|
|
| 153 |
return $var_value; |
return $var_value; |
| 154 |
} |
} |
| 155 |
|
|
| 156 |
|
// TODO: refactor this to Data::Deep |
| 157 |
function _setldsvar($ldskey, $val) { |
function _setldsvar($ldskey, $val) { |
| 158 |
$var_name = '$this->lds' . $ldskey; |
$var_name = '$this->lds' . $ldskey; |
| 159 |
$value_new = addslashes($val); |
$value_new = addslashes($val); |
| 164 |
} |
} |
| 165 |
|
|
| 166 |
function _loadStructure_FromDb() { |
function _loadStructure_FromDb() { |
| 167 |
global $site; |
$this->site->log( get_class($this) . "->_loadStructure_FromDb: Loading language information (l10n) for '$this->langkey'.", PEAR_LOG_DEBUG); |
|
$site->log( get_class($this) . "->_loadStructure_FromDb loading language information", LOG_DEBUG); |
|
|
//print "- loading structure from db ($this->langkey)<br>"; |
|
|
//connectdb(); |
|
| 168 |
$sql = "SELECT * FROM td_res_langtext WHERE countrykey='" . $this->langkey . "'"; |
$sql = "SELECT * FROM td_res_langtext WHERE countrykey='" . $this->langkey . "'"; |
| 169 |
if ($result = $site->db->query($sql)) { |
if ($result = $this->site->db->query($sql)) { |
| 170 |
|
|
| 171 |
|
// pre-flight check: Is $result an object of class "db_error"? |
| 172 |
|
if (get_class($result) == 'db_error') { |
| 173 |
|
// FIXME: How to handle this here??? |
| 174 |
|
//print "Sorry.<br/>"; |
| 175 |
|
$this->site->log( get_class($this) . "->_loadStructure_FromDb: Error while issuing '$sql'.", PEAR_LOG_ERR); |
| 176 |
|
return; |
| 177 |
|
} |
| 178 |
|
|
| 179 |
//while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { |
//while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { |
| 180 |
|
//print Dumper($result); |
| 181 |
while ( $result->fetchInto($row) ) { |
while ( $result->fetchInto($row) ) { |
| 182 |
//print $row[tval]."<br>"; |
//print $row[tval]."<br>"; |
| 183 |
//print_r($row) . "<br>"; |
//print_r($row) . "<br>"; |
| 184 |
$this->_loadStructure_FromDb_add($row["tkey"], $row["tval"]); |
$this->_loadStructure_FromDb_add($row["tkey"], $row["tval"]); |
| 185 |
} |
} |
| 186 |
} |
} |
| 187 |
$site->log( get_class($this) . "->_loadStructure_FromDb ready", LOG_DEBUG); |
$this->site->log( get_class($this) . "->_loadStructure_FromDb ready", PEAR_LOG_DEBUG); |
| 188 |
} |
} |
| 189 |
|
|
| 190 |
function _loadStructure_FromDb_add($dbkey, $val) { |
function _loadStructure_FromDb_add($dbkey, $val) { |
| 232 |
return $this->lds; |
return $this->lds; |
| 233 |
} |
} |
| 234 |
|
|
| 235 |
function getlt($key, $tpl=array()) { |
function getlt($key, $tpl=array(), $newMode = 0) { |
| 236 |
//dprint("getlt: $key"); |
//dprint("getlt: $key"); |
| 237 |
if ($ldskey = $this->_dbkey2ldskey($key)) { |
if ($ldskey = $this->_dbkey2ldskey($key)) { |
| 238 |
return $this->_getldsvar($ldskey, $tpl); |
return $this->_getldsvar($ldskey, $tpl, $newMode); |
| 239 |
} |
} |
| 240 |
} |
} |
| 241 |
|
|
| 242 |
} |
} |
| 243 |
|
|
| 244 |
|
|
| 245 |
|
|
| 246 |
|
/* |
| 247 |
|
Example 13-17. register_block |
| 248 |
|
taken from: http://smarty.php.net/manual/en/api.register.block.html |
| 249 |
|
will be triggered by this template-code: |
| 250 |
|
{* template *} |
| 251 |
|
{translate lang="br"} |
| 252 |
|
Hello, world! |
| 253 |
|
{/translate} |
| 254 |
|
*/ |
| 255 |
|
|
| 256 |
|
/* PHP */ |
| 257 |
|
//global $smarty; |
| 258 |
|
//$smarty->register_block("translate", "do_translation"); |
| 259 |
|
|
| 260 |
|
/* |
| 261 |
|
function _do_translation ($params, $content, &$smarty) { |
| 262 |
|
print "do_translation<br>"; |
| 263 |
|
print "params: " . Dumper($params) . "<br>"; |
| 264 |
|
print "content: $content<br>"; |
| 265 |
|
if ($content) { |
| 266 |
|
//$lang = $params['lang']; |
| 267 |
|
// do some translation with $content |
| 268 |
|
//echo $translation; |
| 269 |
|
return getlt($content); |
| 270 |
|
} |
| 271 |
|
} |
| 272 |
|
*/ |
| 273 |
|
|
| 274 |
?> |
?> |