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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Tue Dec 3 03:10:21 2002 UTC (21 years, 9 months ago) by joko
Branch: MAIN
Changes since 1.1: +12 -6 lines
+ bugfix regarding new object hierarchy

1 joko 1.1 <?
2     // -----------------------------------------------------------------
3 joko 1.2 // $Id: LocaleText.php,v 1.1 2002/11/12 05:42:30 joko Exp $
4 joko 1.1 // ------------------------------------------------------------------
5 joko 1.2 // $Log: LocaleText.php,v $
6     // Revision 1.1 2002/11/12 05:42:30 joko
7     // + initial checkin
8     //
9 joko 1.1 // Revision 1.9 2002/10/25 11:47:50 cvsmax
10     // + modificate function getlt() to get variables in language related content work
11     //
12     // Revision 1.8 2002/07/27 00:31:10 cvsjoko
13     // *** empty log message ***
14     //
15     // Revision 1.7 2002/07/19 18:17:30 cvsjoko
16     // + changes for pre r0.01
17     //
18     // Revision 1.6 2002/06/27 02:27:57 cvsjoko
19     // + bugfix: couldn't use php-keywords as keys due to lack of quoting
20     //
21     // Revision 1.5 2002/06/25 04:25:28 cvsjoko
22     // + added error handling: load structure only if connection to db possible
23     //
24     // Revision 1.4 2002/06/24 14:28:59 cvsmax
25     // + bugfixing
26     //
27     // Revision 1.3 2002/06/23 05:23:02 cvsmax
28     // + add func 'user-session timeout' and extended (user) session logging
29     //
30     // Revision 1.2 2002/06/19 18:16:14 cvsmax
31     // + import to cvs
32     //
33     // ------------------------------------------------------------------
34    
35    
36     class LocaleText {
37    
38     // current selected language
39     var $langkey;
40    
41     // language-data-structure (hash)
42     var $lds;
43    
44     // available languages
45     var $langs_avail;
46    
47     // ----------------------------------------------------
48     function LocaleText() {
49     global $cfg, $slt;
50 joko 1.2 session_register_safe('slt');
51 joko 1.1 $this->langs_avail = $cfg[GLBL_LANGSAVAIL];
52     $this->load();
53     }
54    
55     // ----------------------------------------------------
56     function _detectLanguage() {
57     // detect language from Browser
58     // HACK
59     $browserLang = "tr";
60     // if there is a browser-language set the current language to this one
61     if ($browserLang) {
62     // TODO: log this
63     //print "- detecting browser-language: $browserLang<br>";
64     return $browserLang;
65     }
66     }
67    
68     // ----------------------------------------------------
69     function _findAvailableLanguage($newlang = "") {
70     // check against available languages ...
71     $langs_avail = $this->langs_avail;
72     if (!( is_array($langs_avail) && count($langs_avail) > 0 )) {
73     // TODO: log this
74     print "error with multi-language-system, maybe \"GLBL_LANGSAVAIL\" is not properly configured?<br>";
75     return;
76     }
77     if (in_array($newlang, $langs_avail)) {
78     // ... take the new one, if available, ...
79     return $newlang;
80     } else {
81     // ... or take the first one as a default
82     return $langs_avail[0];
83     }
84     }
85    
86     function _dbkey2ldskey($dbkey) {
87     // TODO: log this
88     //dprint("dbkey: $dbkey");
89     //if (!$dbkey) { return; }
90     if(substr($dbkey,0,1)=="/") { $dbkey=substr($dbkey,1); }
91     $dbkey_arr = split('/', $dbkey);
92     $ldskey = "['" . join("']['", $dbkey_arr) . "']";
93     // return only if key is valid for php!!!
94     if (!stristr($ldskey, '[]')) {
95     return $ldskey;
96     }
97     }
98    
99     function _getldsvar($ldskey, $tpl=array()) {
100     $var_name = '$this->lds' . $ldskey;
101     $eval_string = "return $var_name;";
102     //print $eval_string . "<br>";
103     // interpolate variable-name
104     $var_value = eval($eval_string);
105     // interpolate variable-value to do some template-vars
106     $var_value = eval("return \"$var_value\";");
107     // print $eval_string."<br>";
108     //$var_value = $$var_name;
109     return $var_value;
110     }
111    
112     function _setldsvar($ldskey, $val) {
113     $var_name = '$this->lds' . $ldskey;
114     $value_new = addslashes($val);
115     $eval_string = "$var_name = '$value_new';";
116     //print $eval_string . "<br>";
117     eval($eval_string);
118     //$$var_name = $value_new;
119     }
120    
121     function _loadStructure_FromDb() {
122     global $site;
123     $site->log( get_class($this) . "->_loadStructure_FromDb loading language information", LOG_DEBUG);
124     //print "- loading structure from db ($this->langkey)<br>";
125     //connectdb();
126     $sql = "SELECT * FROM td_res_langtext WHERE countrykey='" . $this->langkey . "'";
127     if ($result = $site->db->query($sql)) {
128     //while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
129     while ( $result->fetchInto($row) ) {
130     //print $row[tval]."<br>";
131     //print_r($row) . "<br>";
132     $this->_loadStructure_FromDb_add($row["tkey"], $row["tval"]);
133     }
134     }
135     $site->log( get_class($this) . "->_loadStructure_FromDb ready", LOG_DEBUG);
136     }
137    
138     function _loadStructure_FromDb_add($dbkey, $val) {
139     $ldskey = $this->_dbkey2ldskey($dbkey);
140     $this->_setldsvar($ldskey, $val);
141     }
142    
143    
144    
145     // ========================================
146    
147     function setLanguage($langkey_new = "") {
148     global $slt;
149 joko 1.2 //print "setting lang<br>";
150     if ($langkey_new) {
151 joko 1.1 $slt[langkey] = $langkey_new;
152     }
153 joko 1.2 $this->load();
154 joko 1.1 }
155    
156     function load() {
157     global $slt;
158    
159 joko 1.2 if (!$this->langkey) { $this->langkey = $slt[langkey]; }
160 joko 1.1 if (!$this->langkey) { $this->langkey = $this->_findAvailableLanguage($slt[langkey]); }
161    
162 joko 1.2 //print "- starting language-library<br>";
163     //print "lang: " . $this->langkey . "<br>";
164 joko 1.1 //$langkey_new = $this->_detectLanguage();
165     //$this->_loadStructure_FromDb();
166     //$this->setLanguage($langkey_new);
167    
168     $this->_loadStructure_FromDb();
169     }
170    
171     function getAvailableLanguages() {
172     return $this->langs_avail;
173     }
174    
175     function getCurrentLanguage() {
176     return $this->langkey;
177     }
178    
179     function getLangTexts() {
180     return $this->lds;
181     }
182    
183     function getlt($key, $tpl=array()) {
184     dprint("getlt: $key");
185     if ($ldskey = $this->_dbkey2ldskey($key)) {
186     return $this->_getldsvar($ldskey, $tpl);
187     }
188     }
189    
190     }
191    
192     ?>

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