3 |
// $Id$ |
// $Id$ |
4 |
// ------------------------------------------------------------------ |
// ------------------------------------------------------------------ |
5 |
// $Log$ |
// $Log$ |
6 |
|
// Revision 1.6 2003/02/09 17:33:54 joko |
7 |
|
// + minor update related to new log level constants |
8 |
|
// |
9 |
|
// Revision 1.5 2002/12/19 10:30:06 joko |
10 |
|
// + argument 'newMode' for function getlt and function _getldsvar: let _getldsvar evaluate variable to still provide old behaviour/functionality |
11 |
|
// |
12 |
|
// Revision 1.4 2002/12/19 06:18:40 joko |
13 |
|
// + '$this->site' gets used here now |
14 |
|
// |
15 |
|
// Revision 1.3 2002/12/04 07:40:05 jonen |
16 |
|
// + comment out dprint |
17 |
|
// |
18 |
|
// Revision 1.2 2002/12/03 03:10:21 joko |
19 |
|
// + bugfix regarding new object hierarchy |
20 |
|
// |
21 |
// Revision 1.1 2002/11/12 05:42:30 joko |
// Revision 1.1 2002/11/12 05:42:30 joko |
22 |
// + initial checkin |
// + initial checkin |
23 |
// |
// |
61 |
|
|
62 |
// ---------------------------------------------------- |
// ---------------------------------------------------- |
63 |
function LocaleText() { |
function LocaleText() { |
64 |
global $cfg, $slt; |
|
65 |
//session_register_safe('slt'); |
// look at the bottom of this file!!! |
66 |
$this->langs_avail = $cfg[GLBL_LANGSAVAIL]; |
//$smarty->register_block("translate", "do_translation"); |
67 |
|
//$this->site->smarty->register_block("translate", "_do_translation"); |
68 |
|
|
69 |
|
//global $site; |
70 |
|
//$site->smarty->register_block("translate", "_do_translation"); |
71 |
|
|
72 |
|
} |
73 |
|
|
74 |
|
function start() { |
75 |
|
global $app, $slt; |
76 |
|
session_register_safe('slt'); |
77 |
|
$this->langs_avail = $app->getConfig("languages.available"); |
78 |
$this->load(); |
$this->load(); |
79 |
} |
} |
80 |
|
|
108 |
return $langs_avail[0]; |
return $langs_avail[0]; |
109 |
} |
} |
110 |
} |
} |
111 |
|
|
112 |
|
// TODO: refactor this to Data::Deep |
113 |
function _dbkey2ldskey($dbkey) { |
function _dbkey2ldskey($dbkey) { |
114 |
// TODO: log this |
// TODO: log this |
115 |
//dprint("dbkey: $dbkey"); |
//dprint("dbkey: $dbkey"); |
123 |
} |
} |
124 |
} |
} |
125 |
|
|
126 |
function _getldsvar($ldskey, $tpl=array()) { |
// TODO: refactor this to Data::Deep |
127 |
|
function _getldsvar($ldskey, $tpl=array(), $newMode = 0) { |
128 |
|
|
129 |
|
//print "ldskey: $ldskey<br>"; |
130 |
|
|
131 |
$var_name = '$this->lds' . $ldskey; |
$var_name = '$this->lds' . $ldskey; |
132 |
$eval_string = "return $var_name;"; |
$eval_string = "return $var_name;"; |
133 |
//print $eval_string . "<br>"; |
//print $eval_string . "<br>"; |
134 |
|
|
135 |
// interpolate variable-name |
// interpolate variable-name |
136 |
$var_value = eval($eval_string); |
$var_value = eval($eval_string); |
137 |
// interpolate variable-value to do some template-vars |
// interpolate variable-value to do some template-vars |
138 |
$var_value = eval("return \"$var_value\";"); |
if (!$newMode) { |
139 |
|
$var_value = eval("return \"$var_value\";"); |
140 |
|
} |
141 |
|
|
142 |
|
// V1 - result interpolation using eval |
143 |
// print $eval_string."<br>"; |
// print $eval_string."<br>"; |
144 |
//$var_value = $$var_name; |
//$var_value = $$var_name; |
145 |
|
|
146 |
|
// V2 - result interpolation using smarty |
147 |
|
//print Dumper($tpl); |
148 |
|
//$this->site->loadTemplate(); |
149 |
|
|
150 |
return $var_value; |
return $var_value; |
151 |
} |
} |
152 |
|
|
153 |
|
// TODO: refactor this to Data::Deep |
154 |
function _setldsvar($ldskey, $val) { |
function _setldsvar($ldskey, $val) { |
155 |
$var_name = '$this->lds' . $ldskey; |
$var_name = '$this->lds' . $ldskey; |
156 |
$value_new = addslashes($val); |
$value_new = addslashes($val); |
161 |
} |
} |
162 |
|
|
163 |
function _loadStructure_FromDb() { |
function _loadStructure_FromDb() { |
164 |
global $site; |
//global $site; |
165 |
$site->log( get_class($this) . "->_loadStructure_FromDb loading language information", LOG_DEBUG); |
$this->site->log( get_class($this) . "->_loadStructure_FromDb loading language information", PEAR_LOG_DEBUG); |
166 |
//print "- loading structure from db ($this->langkey)<br>"; |
//print "- loading structure from db ($this->langkey)<br>"; |
167 |
//connectdb(); |
//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 |
//while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { |
//while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { |
171 |
while ( $result->fetchInto($row) ) { |
while ( $result->fetchInto($row) ) { |
172 |
//print $row[tval]."<br>"; |
//print $row[tval]."<br>"; |
174 |
$this->_loadStructure_FromDb_add($row["tkey"], $row["tval"]); |
$this->_loadStructure_FromDb_add($row["tkey"], $row["tval"]); |
175 |
} |
} |
176 |
} |
} |
177 |
$site->log( get_class($this) . "->_loadStructure_FromDb ready", LOG_DEBUG); |
$this->site->log( get_class($this) . "->_loadStructure_FromDb ready", PEAR_LOG_DEBUG); |
178 |
} |
} |
179 |
|
|
180 |
function _loadStructure_FromDb_add($dbkey, $val) { |
function _loadStructure_FromDb_add($dbkey, $val) { |
188 |
|
|
189 |
function setLanguage($langkey_new = "") { |
function setLanguage($langkey_new = "") { |
190 |
global $slt; |
global $slt; |
191 |
if ($langkey_new) { |
//print "setting lang<br>"; |
192 |
|
if ($langkey_new) { |
193 |
$slt[langkey] = $langkey_new; |
$slt[langkey] = $langkey_new; |
194 |
} |
} |
195 |
|
$this->load(); |
196 |
} |
} |
197 |
|
|
198 |
function load() { |
function load() { |
199 |
global $slt; |
global $slt; |
200 |
|
|
201 |
$this->langkey = $slt[langkey]; |
if (!$this->langkey) { $this->langkey = $slt[langkey]; } |
202 |
if (!$this->langkey) { $this->langkey = $this->_findAvailableLanguage($slt[langkey]); } |
if (!$this->langkey) { $this->langkey = $this->_findAvailableLanguage($slt[langkey]); } |
203 |
|
|
204 |
// print "- starting language-library<br>"; |
//print "- starting language-library<br>"; |
205 |
|
//print "lang: " . $this->langkey . "<br>"; |
206 |
//$langkey_new = $this->_detectLanguage(); |
//$langkey_new = $this->_detectLanguage(); |
207 |
//$this->_loadStructure_FromDb(); |
//$this->_loadStructure_FromDb(); |
208 |
//$this->setLanguage($langkey_new); |
//$this->setLanguage($langkey_new); |
222 |
return $this->lds; |
return $this->lds; |
223 |
} |
} |
224 |
|
|
225 |
function getlt($key, $tpl=array()) { |
function getlt($key, $tpl=array(), $newMode = 0) { |
226 |
dprint("getlt: $key"); |
//dprint("getlt: $key"); |
227 |
if ($ldskey = $this->_dbkey2ldskey($key)) { |
if ($ldskey = $this->_dbkey2ldskey($key)) { |
228 |
return $this->_getldsvar($ldskey, $tpl); |
return $this->_getldsvar($ldskey, $tpl, $newMode); |
229 |
} |
} |
230 |
} |
} |
231 |
|
|
232 |
} |
} |
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
/* |
237 |
|
Example 13-17. register_block |
238 |
|
taken from: http://smarty.php.net/manual/en/api.register.block.html |
239 |
|
will be triggered by this template-code: |
240 |
|
{* template *} |
241 |
|
{translate lang="br"} |
242 |
|
Hello, world! |
243 |
|
{/translate} |
244 |
|
*/ |
245 |
|
|
246 |
|
/* PHP */ |
247 |
|
//global $smarty; |
248 |
|
//$smarty->register_block("translate", "do_translation"); |
249 |
|
|
250 |
|
/* |
251 |
|
function _do_translation ($params, $content, &$smarty) { |
252 |
|
print "do_translation<br>"; |
253 |
|
print "params: " . Dumper($params) . "<br>"; |
254 |
|
print "content: $content<br>"; |
255 |
|
if ($content) { |
256 |
|
//$lang = $params['lang']; |
257 |
|
// do some translation with $content |
258 |
|
//echo $translation; |
259 |
|
return getlt($content); |
260 |
|
} |
261 |
|
} |
262 |
|
*/ |
263 |
|
|
264 |
?> |
?> |