3 |
// $Id$ |
// $Id$ |
4 |
// ------------------------------------------------------------------ |
// ------------------------------------------------------------------ |
5 |
// $Log$ |
// $Log$ |
6 |
|
// Revision 1.4 2002/12/19 06:18:40 joko |
7 |
|
// + '$this->site' gets used here now |
8 |
|
// |
9 |
|
// Revision 1.3 2002/12/04 07:40:05 jonen |
10 |
|
// + comment out dprint |
11 |
|
// |
12 |
|
// Revision 1.2 2002/12/03 03:10:21 joko |
13 |
|
// + bugfix regarding new object hierarchy |
14 |
|
// |
15 |
// Revision 1.1 2002/11/12 05:42:30 joko |
// Revision 1.1 2002/11/12 05:42:30 joko |
16 |
// + initial checkin |
// + initial checkin |
17 |
// |
// |
55 |
|
|
56 |
// ---------------------------------------------------- |
// ---------------------------------------------------- |
57 |
function LocaleText() { |
function LocaleText() { |
58 |
|
|
59 |
|
/* |
60 |
|
// was: |
61 |
|
global $cfg, $slt; |
62 |
|
session_register_safe('slt'); |
63 |
|
$this->langs_avail = $cfg[GLBL_LANGSAVAIL]; |
64 |
|
$this->load(); |
65 |
|
*/ |
66 |
|
|
67 |
|
// look at the bottom of this file!!! |
68 |
|
//$smarty->register_block("translate", "do_translation"); |
69 |
|
//$this->site->smarty->register_block("translate", "_do_translation"); |
70 |
|
|
71 |
|
//global $site; |
72 |
|
//$site->smarty->register_block("translate", "_do_translation"); |
73 |
|
|
74 |
|
} |
75 |
|
|
76 |
|
function start() { |
77 |
global $cfg, $slt; |
global $cfg, $slt; |
78 |
//session_register_safe('slt'); |
session_register_safe('slt'); |
79 |
$this->langs_avail = $cfg[GLBL_LANGSAVAIL]; |
$this->langs_avail = $cfg[GLBL_LANGSAVAIL]; |
80 |
$this->load(); |
$this->load(); |
81 |
} |
} |
125 |
} |
} |
126 |
|
|
127 |
function _getldsvar($ldskey, $tpl=array()) { |
function _getldsvar($ldskey, $tpl=array()) { |
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\";"); |
//$var_value = eval("return \"$var_value\";"); |
139 |
|
|
140 |
|
// V1 - result interpolation using eval |
141 |
// print $eval_string."<br>"; |
// print $eval_string."<br>"; |
142 |
//$var_value = $$var_name; |
//$var_value = $$var_name; |
143 |
|
|
144 |
|
// V2 - result interpolation using smarty |
145 |
|
//print Dumper($tpl); |
146 |
|
//$this->site->loadTemplate(); |
147 |
|
|
148 |
return $var_value; |
return $var_value; |
149 |
} |
} |
150 |
|
|
158 |
} |
} |
159 |
|
|
160 |
function _loadStructure_FromDb() { |
function _loadStructure_FromDb() { |
161 |
global $site; |
//global $site; |
162 |
$site->log( get_class($this) . "->_loadStructure_FromDb loading language information", LOG_DEBUG); |
$this->site->log( get_class($this) . "->_loadStructure_FromDb loading language information", LOG_DEBUG); |
163 |
//print "- loading structure from db ($this->langkey)<br>"; |
//print "- loading structure from db ($this->langkey)<br>"; |
164 |
//connectdb(); |
//connectdb(); |
165 |
$sql = "SELECT * FROM td_res_langtext WHERE countrykey='" . $this->langkey . "'"; |
$sql = "SELECT * FROM td_res_langtext WHERE countrykey='" . $this->langkey . "'"; |
166 |
if ($result = $site->db->query($sql)) { |
if ($result = $this->site->db->query($sql)) { |
167 |
//while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { |
//while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { |
168 |
while ( $result->fetchInto($row) ) { |
while ( $result->fetchInto($row) ) { |
169 |
//print $row[tval]."<br>"; |
//print $row[tval]."<br>"; |
171 |
$this->_loadStructure_FromDb_add($row["tkey"], $row["tval"]); |
$this->_loadStructure_FromDb_add($row["tkey"], $row["tval"]); |
172 |
} |
} |
173 |
} |
} |
174 |
$site->log( get_class($this) . "->_loadStructure_FromDb ready", LOG_DEBUG); |
$this->site->log( get_class($this) . "->_loadStructure_FromDb ready", LOG_DEBUG); |
175 |
} |
} |
176 |
|
|
177 |
function _loadStructure_FromDb_add($dbkey, $val) { |
function _loadStructure_FromDb_add($dbkey, $val) { |
185 |
|
|
186 |
function setLanguage($langkey_new = "") { |
function setLanguage($langkey_new = "") { |
187 |
global $slt; |
global $slt; |
188 |
if ($langkey_new) { |
//print "setting lang<br>"; |
189 |
|
if ($langkey_new) { |
190 |
$slt[langkey] = $langkey_new; |
$slt[langkey] = $langkey_new; |
191 |
} |
} |
192 |
|
$this->load(); |
193 |
} |
} |
194 |
|
|
195 |
function load() { |
function load() { |
196 |
global $slt; |
global $slt; |
197 |
|
|
198 |
$this->langkey = $slt[langkey]; |
if (!$this->langkey) { $this->langkey = $slt[langkey]; } |
199 |
if (!$this->langkey) { $this->langkey = $this->_findAvailableLanguage($slt[langkey]); } |
if (!$this->langkey) { $this->langkey = $this->_findAvailableLanguage($slt[langkey]); } |
200 |
|
|
201 |
// print "- starting language-library<br>"; |
//print "- starting language-library<br>"; |
202 |
|
//print "lang: " . $this->langkey . "<br>"; |
203 |
//$langkey_new = $this->_detectLanguage(); |
//$langkey_new = $this->_detectLanguage(); |
204 |
//$this->_loadStructure_FromDb(); |
//$this->_loadStructure_FromDb(); |
205 |
//$this->setLanguage($langkey_new); |
//$this->setLanguage($langkey_new); |
220 |
} |
} |
221 |
|
|
222 |
function getlt($key, $tpl=array()) { |
function getlt($key, $tpl=array()) { |
223 |
dprint("getlt: $key"); |
//dprint("getlt: $key"); |
224 |
if ($ldskey = $this->_dbkey2ldskey($key)) { |
if ($ldskey = $this->_dbkey2ldskey($key)) { |
225 |
return $this->_getldsvar($ldskey, $tpl); |
return $this->_getldsvar($ldskey, $tpl); |
226 |
} |
} |
228 |
|
|
229 |
} |
} |
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
/* |
234 |
|
Example 13-17. register_block |
235 |
|
taken from: http://smarty.php.net/manual/en/api.register.block.html |
236 |
|
will be triggered by this template-code: |
237 |
|
{* template *} |
238 |
|
{translate lang="br"} |
239 |
|
Hello, world! |
240 |
|
{/translate} |
241 |
|
*/ |
242 |
|
|
243 |
|
/* PHP */ |
244 |
|
//global $smarty; |
245 |
|
//$smarty->register_block("translate", "do_translation"); |
246 |
|
|
247 |
|
/* |
248 |
|
function _do_translation ($params, $content, &$smarty) { |
249 |
|
print "do_translation<br>"; |
250 |
|
print "params: " . Dumper($params) . "<br>"; |
251 |
|
print "content: $content<br>"; |
252 |
|
if ($content) { |
253 |
|
//$lang = $params['lang']; |
254 |
|
// do some translation with $content |
255 |
|
//echo $translation; |
256 |
|
return getlt($content); |
257 |
|
} |
258 |
|
} |
259 |
|
*/ |
260 |
|
|
261 |
?> |
?> |