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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Tue Nov 12 05:42:30 2002 UTC (21 years, 10 months ago) by joko
Branch: MAIN
+ initial checkin

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

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