/[cvs]/nfo/php/libs/org.netfrag.flib/Application/l10n/LocaleText.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.flib/Application/l10n/LocaleText.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by joko, Tue Nov 12 05:42:30 2002 UTC revision 1.5 by joko, Thu Dec 19 10:30:06 2002 UTC
# Line 3  Line 3 
3  //    $Id$  //    $Id$
4  //    ------------------------------------------------------------------  //    ------------------------------------------------------------------
5  //    $Log$  //    $Log$
6    //    Revision 1.5  2002/12/19 10:30:06  joko
7    //    + argument 'newMode' for function getlt and function _getldsvar: let _getldsvar evaluate variable to still provide old behaviour/functionality
8    //
9    //    Revision 1.4  2002/12/19 06:18:40  joko
10    //    + '$this->site' gets used here now
11    //
12    //    Revision 1.3  2002/12/04 07:40:05  jonen
13    //    + comment out dprint
14    //
15    //    Revision 1.2  2002/12/03 03:10:21  joko
16    //    + bugfix regarding new object hierarchy
17    //
18  //    Revision 1.1  2002/11/12 05:42:30  joko  //    Revision 1.1  2002/11/12 05:42:30  joko
19  //    + initial checkin  //    + initial checkin
20  //  //
# Line 46  class LocaleText { Line 58  class LocaleText {
58        
59    // ----------------------------------------------------    // ----------------------------------------------------
60    function LocaleText() {    function LocaleText() {
61    
62        /*
63        // was:
64        global $cfg, $slt;
65        session_register_safe('slt');
66        $this->langs_avail = $cfg[GLBL_LANGSAVAIL];
67        $this->load();
68        */
69        
70        // look at the bottom of this file!!!
71        //$smarty->register_block("translate", "do_translation");
72        //$this->site->smarty->register_block("translate", "_do_translation");
73    
74        //global $site;
75        //$site->smarty->register_block("translate", "_do_translation");
76    
77      }
78    
79      function start() {
80      global $cfg, $slt;      global $cfg, $slt;
81      //session_register_safe('slt');      session_register_safe('slt');
82      $this->langs_avail = $cfg[GLBL_LANGSAVAIL];      $this->langs_avail = $cfg[GLBL_LANGSAVAIL];
83      $this->load();      $this->load();
84    }    }
# Line 96  class LocaleText { Line 127  class LocaleText {
127      }      }
128    }    }
129        
130    function _getldsvar($ldskey, $tpl=array()) {    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        
# Line 119  class LocaleText { Line 163  class LocaleText {
163    }    }
164        
165    function _loadStructure_FromDb() {    function _loadStructure_FromDb() {
166      global $site;      //global $site;
167      $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);
168      //print "- loading structure from db ($this->langkey)<br>";      //print "- loading structure from db ($this->langkey)<br>";
169      //connectdb();      //connectdb();
170      $sql = "SELECT * FROM td_res_langtext WHERE countrykey='" . $this->langkey . "'";      $sql = "SELECT * FROM td_res_langtext WHERE countrykey='" . $this->langkey . "'";
171      if ($result = $site->db->query($sql)) {      if ($result = $this->site->db->query($sql)) {
172        //while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {        //while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
173        while ( $result->fetchInto($row) ) {        while ( $result->fetchInto($row) ) {
174           //print $row[tval]."<br>";           //print $row[tval]."<br>";
# Line 132  class LocaleText { Line 176  class LocaleText {
176            $this->_loadStructure_FromDb_add($row["tkey"], $row["tval"]);            $this->_loadStructure_FromDb_add($row["tkey"], $row["tval"]);
177        }        }
178      }      }
179      $site->log( get_class($this) . "->_loadStructure_FromDb ready", LOG_DEBUG);      $this->site->log( get_class($this) . "->_loadStructure_FromDb ready", LOG_DEBUG);
180    }    }
181        
182    function _loadStructure_FromDb_add($dbkey, $val) {    function _loadStructure_FromDb_add($dbkey, $val) {
# Line 146  class LocaleText { Line 190  class LocaleText {
190    
191    function setLanguage($langkey_new = "") {    function setLanguage($langkey_new = "") {
192      global $slt;      global $slt;
193      if ($langkey_new) {      //print "setting lang<br>";
194        if ($langkey_new) {
195        $slt[langkey] = $langkey_new;        $slt[langkey] = $langkey_new;
196      }      }
197        $this->load();
198    }    }
199        
200    function load() {    function load() {
201      global $slt;      global $slt;
202    
203      $this->langkey = $slt[langkey];      if (!$this->langkey) { $this->langkey = $slt[langkey]; }
204      if (!$this->langkey) { $this->langkey = $this->_findAvailableLanguage($slt[langkey]); }      if (!$this->langkey) { $this->langkey = $this->_findAvailableLanguage($slt[langkey]); }
205    
206      // print "- starting language-library<br>";      //print "- starting language-library<br>";
207        //print "lang: " . $this->langkey . "<br>";
208      //$langkey_new = $this->_detectLanguage();      //$langkey_new = $this->_detectLanguage();
209      //$this->_loadStructure_FromDb();      //$this->_loadStructure_FromDb();
210      //$this->setLanguage($langkey_new);      //$this->setLanguage($langkey_new);
# Line 177  class LocaleText { Line 224  class LocaleText {
224      return $this->lds;      return $this->lds;
225    }    }
226        
227    function getlt($key, $tpl=array()) {    function getlt($key, $tpl=array(), $newMode = 0) {
228      dprint("getlt: $key");      //dprint("getlt: $key");
229      if ($ldskey = $this->_dbkey2ldskey($key)) {      if ($ldskey = $this->_dbkey2ldskey($key)) {
230        return $this->_getldsvar($ldskey, $tpl);        return $this->_getldsvar($ldskey, $tpl, $newMode);
231      }      }
232    }    }
233    
234  }  }
235    
236    
237    
238    /*
239    Example 13-17. register_block
240    taken from: http://smarty.php.net/manual/en/api.register.block.html
241    will be triggered by this template-code:
242      {* template *}
243      {translate lang="br"}
244         Hello, world!
245      {/translate}
246    */
247    
248      /* PHP */
249      //global $smarty;
250      //$smarty->register_block("translate", "do_translation");
251    
252    /*  
253      function _do_translation ($params, $content, &$smarty) {
254          print "do_translation<br>";
255          print "params: " . Dumper($params) . "<br>";
256          print "content: $content<br>";
257          if ($content) {
258              //$lang = $params['lang'];
259              // do some translation with $content
260              //echo $translation;
261              return getlt($content);
262          }
263      }
264    */
265      
266  ?>  ?>

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.5

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed