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->jerror("LOGIN-NOAUTH", "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;
89 /// verify the selected language..
90 $i = DB_DataObject::Factory('I18n');
91 $i->ltype = 'l'; // string(1) not_null multiple_key
92 $i->lkey = $lang; // string(8) not_null
94 $i = DB_DataObject::Factory('I18n');
97 $i = DB_DataObject::Factory('I18n');
98 $i->ltype = 'l'; // string(1) not_null multiple_key
101 $this->jerr('invalid lang configured: ' . $lang);
106 return explode('_', $lang);
109 function get($s ='', $opts=array())
112 $this->sessionState(0);
113 $lbits = $this->guessUsersLanguage();
115 if ($this->authUser && !empty($_REQUEST['_debug'])) {
116 DB_DataObject::debugLevel(1);
121 $i = DB_DataObject::Factory('I18n');
128 $i->applyFilters($_REQUEST, $this->authUser, $this);
129 $this->jdata($i->toTransList('l', implode('_',$lbits)));
134 $i->applyFilters($_REQUEST, $this->authUser, $this);
135 $this->jdata($i->toTransList('c', implode('_',$lbits)));
141 $i->applyFilters($_REQUEST, $this->authUser, $this);
142 $this->jdata($i->toTransList('m', implode('_',$lbits)));
146 $ar = DateTimeZone::listAbbreviations();
149 foreach($ar as $tl => $sar) {
150 foreach($sar as $tz) {
151 $tza[] = $tz['timezone_id'];
155 $tza= array_unique($tza);
157 foreach($tza as $tz) {
159 if (empty($_REQUEST['q']) ||
161 substr($tz,0, strlen($_REQUEST['q'])),
164 $ret[] = array('tz' => $tz);
175 if (!empty($_REQUEST['debug'])) {
176 DB_DataObject::debugLevel(1);
179 $i = DB_DataObject::Factory('I18n');
183 $i = DB_DataObject::Factory('I18n');
186 // var_dump($langs);exit;
188 foreach($langs as $lang)
190 //$rlang = array_shift(explode('_', strtoupper($lang)));
191 $ll = explode('_', $lang);
192 $rlang = array_shift($ll);
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 require_once 'I18Nv2/CurrencyMap.php';
204 $ar['currency_map'] = I18Nv2_CurrencyMap::$s_map;
206 //echo '<PRE>';print_r($ar);
207 header('Content-type: text/javascript');
208 echo "Roo.namespace('Pman.I18n');";
209 echo 'Pman.I18n.Data = ' . json_encode($ar);
219 * translate (used by database building);
221 * require_once 'Pman/Core/I18n.php';
222 * $x = new Pman_Core_I18N();
223 * $x->translate($this->authuser, 'c', 'US');
224 * @param au - auth User
225 * @param type = 'c' or 'l'
226 * @param k - key to translate
230 function translate($au, $type, $k)
238 if(class_exists('HTML_FlexyFramework2', false)) {
239 $fo = HTML_FlexyFramework2::get()->HTML_Template_Flexy;
242 $fo = &PEAR::getStaticProperty('HTML_Template_Flexy','options');
245 $fallback_lang = empty($fo['locale']) ? 'en' : $fo['locale'];
248 $lang = empty($au ) ? $fallback_lang : (is_string($au) ? $au : $au->lang);
250 // does it need caching?
252 $i = DB_DataObject::Factory('I18n');
253 return $i->translate($lang,$type,$k);
261 * translate a list of items
262 * @param Pman_Core_DataObjects_Person $au Authenticated user
263 * @param String $type c/l/m
264 * @param String $k 'comma' seperated list of keys to translate
267 function translateList($au, $type, $k)
269 $ar = explode(',', $k);
271 foreach($ar as $kk) {
272 $ret[] = $this->translate($au, $type, $kk);
274 return implode(', ', $ret);
277 * DO NOT USE THIS -- see core_curr_rates dataobject.
281 function convertCurrency($val, $from, $to)
284 return DB_DAtaObject::Factory('core_curr_rate')->convert($val,$from,$to);
288 * DO NOT USE THIS -- see core_curr_rates dataobject.
296 static $rates = array();
298 if (!empty($rates)) {
299 $this->rates = $rates;
303 $this->rates = $rates = DB_DAtaObject::Factory('core_curr_rate')->currentRates();