4 * Either we load this as a standard array at start??
7 * We basically load up all supported languages at the start of the application.
9 * By default it returns
14 l : [ { code : 'en', title : 'English' }, .... ],
15 c : [ { code : 'UK', title : 'United Kingdom' }, .... ],
16 m : [ { code : 'USD', title : 'US Dollars' }, .... ],
23 * index.php/Pman/I18N/BuildDB -- buildes the database..
24 * .. other formats are depreciated, but are supported by the old code....
27 * Database language translation should be done using the database table.
28 * So sorting can be done correctly..
30 * Configuration in index.php..
32 * 'Pman_Core_I18N' => array(
34 'en', 'zh_CN', 'zh_HK', 'zh_TW', 'th', 'ko', 'ja', 'ms',
42 'c' => '*', // eg. all languages..
43 'm' => array( 'USD', 'HKD', 'GBP', 'CNY', 'SGD', 'JPY' )
48 require_once 'Pman.php';
50 class Pman_Core_I18n extends Pman
61 parent::getAuth(); // load company!
63 $au = $this->getAuthUser();
65 // $this->jerr("Not authenticated", array('authFailure' => true));
67 $this->authUser = $au;
69 $ff= HTML_FlexyFramework::get();
72 $opts = empty($ff->Pman_Core_I18N) ?
73 (empty($ff->Pman_I18N) ? array() : $ff->Pman_I18N)
74 : $ff->Pman_Core_I18N;
84 function guessUsersLanguage()
86 $this->sessionState(0);
88 $lang = !$this->authUser || empty($this->authUser->lang ) ? 'en' : $this->authUser->lang;
90 /// verify the selected language..
91 $i = DB_DataObject::Factory('I18n');
92 $i->ltype = 'l'; // string(1) not_null multiple_key
93 $i->lkey = $lang; // string(8) not_null
95 $i = DB_DataObject::Factory('I18n');
98 $i = DB_DataObject::Factory('I18n');
99 $i->ltype = 'l'; // string(1) not_null multiple_key
102 $this->jerr('invalid lang configured: ' . $lang);
107 return explode('_', $lang);
113 $this->sessionState(0);
114 $lbits = $this->guessUsersLanguage();
116 if ($this->authUser && !empty($_REQUEST['_debug'])) {
117 DB_DataObject::debugLevel(1);
122 $i = DB_DataObject::Factory('I18n');
129 $i->applyFilters($_REQUEST, $this->authUser, $this);
130 $this->jdata($i->toTransList('l', implode('_',$lbits)));
135 $i->applyFilters($_REQUEST, $this->authUser, $this);
136 $this->jdata($i->toTransList('c', implode('_',$lbits)));
142 $i->applyFilters($_REQUEST, $this->authUser, $this);
143 $this->jdata($i->toTransList('m', implode('_',$lbits)));
147 $ar = DateTimeZone::listAbbreviations();
150 foreach($ar as $tl => $sar) {
151 foreach($sar as $tz) {
152 $tza[] = $tz['timezone_id'];
156 $tza= array_unique($tza);
158 foreach($tza as $tz) {
160 if (empty($_REQUEST['q']) ||
162 substr($tz,0, strlen($_REQUEST['q'])),
165 $ret[] = array('tz' => $tz);
176 if (!empty($_REQUEST['debug'])) {
177 DB_DataObject::debugLevel(1);
180 $i = DB_DataObject::Factory('I18n');
184 $i = DB_DataObject::Factory('I18n');
187 // var_dump($langs);exit;
189 foreach($langs as $lang)
191 //$rlang = array_shift(explode('_', strtoupper($lang)));
192 $rlang = array_shift(explode('_', $lang));
194 $ar[$lang] = array();
195 $i = DB_DataObject::Factory('I18n');
196 $ar[$lang]['l'] = $i->toTransList('l', $rlang);
197 $i = DB_DataObject::Factory('I18n');
198 $ar[$lang]['c'] = $i->toTransList('c', $rlang);
199 $i = DB_DataObject::Factory('I18n');
200 $ar[$lang]['m'] = $i->toTransList('m', $rlang);
202 //echo '<PRE>';print_r($ar);
203 header('Content-type: text/javascript');
204 echo 'Pman.I18n.Data = ' . json_encode($ar);
214 * translate (used by database building);
216 * require_once 'Pman/Core/I18n.php';
217 * $x = new Pman_Core_I18N();
218 * $x->translate($this->authuser, 'c', 'US');
219 * @param au - auth User
220 * @param type = 'c' or 'l'
221 * @param k - key to translate
225 function translate($au, $type, $k)
232 $lang = !$au || empty($au->lang ) ? 'en' : is_string($au) ? $au : $au->lang;
234 // does it need caching?
236 $i = DB_DataObject::Factory('I18n');
237 return $i->translate($lang,$type,$k);
245 * translate a list of items
246 * @param Pman_Core_DataObjects_Person $au Authenticated user
247 * @param String $type c/l/m
248 * @param String $k 'comma' seperated list of keys to translate
251 function translateList($au, $type, $k)
253 $ar = explode(',', $k);
255 foreach($ar as $kk) {
256 $ret[] = $this->translate($au, $type, $kk);
258 return implode(', ', $ret);
261 * DO NOT USE THIS -- see core_curr_rates dataobject.
265 function convertCurrency($val, $from, $to)
268 return DB_DAtaObject::Factory('core_curr_rate')->convert($val,$from,$to);
272 * DO NOT USE THIS -- see core_curr_rates dataobject.
280 static $rates = array();
282 if (!empty($rates)) {
283 $this->rates = $rates;
287 $this->rates = $rates = DB_DAtaObject::Factory('core_curr_rate')->currentRates();