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 $lang = !$this->authUser || empty($this->authUser->lang ) ? 'en' : $this->authUser->lang;
88 /// verify the selected language..
89 $i = DB_DataObject::Factory('I18n');
90 $i->ltype = 'l'; // string(1) not_null multiple_key
91 $i->lkey = $lang; // string(8) not_null
93 $i = DB_DataObject::Factory('I18n');
95 $i = DB_DataObject::Factory('I18n');
96 $i->ltype = 'l'; // string(1) not_null multiple_key
99 $this->jerr('invalid lang configured: ' . $lang);
104 return explode('_', $lang);
111 $lbits = $this->guessUsersLanguage();
114 $i = DB_DataObject::Factory('I18n');
119 $i->applyFilters($_REQUEST, $this->authUser, $this);
120 $this->jdata($i->toTransList('l', $lbits[0]));
125 $i->applyFilters($_REQUEST, $this->authUser, $this);
126 $this->jdata($i->toTransList('c', $lbits[0]));
128 $ret = $this->getList('c', $lbits[0],empty($_REQUEST['filter']) ? false : $_REQUEST['filter']);
133 $i->applyFilters($_REQUEST, $this->authUser, $this);
134 $this->jdata($i->toTransList('m', $lbits[0]));
140 $i = DB_DataObject::Factory('I18n');
144 $i = DB_DataObject::Factory('I18n');
147 // var_dump($langs);exit;
149 foreach($langs as $lang)
151 $rlang = array_shift(explode('_', strtoupper($lang)));
153 $ar[$lang] = array();
154 $i = DB_DataObject::Factory('I18n');
155 $ar[$lang]['l'] = $i->toTransList('l', $rlang);
156 $i = DB_DataObject::Factory('I18n');
157 $ar[$lang]['c'] = $i->toTransList('c', $rlang);
158 $i = DB_DataObject::Factory('I18n');
159 $ar[$lang]['m'] = $i->toTransList('m', $rlang);
161 //echo '<PRE>';print_r($ar);
162 header('Content-type: text/javascript');
163 echo 'Pman.I18n.Data = ' . json_encode($ar);
173 * translate (used by database building);
175 * require_once 'Pman/Core/I18N.php';
176 * $x = new Pman_Core_I18N();
177 * $x->translate($this->authuser, 'c', 'US');
178 * @param au - auth User
179 * @param type = 'c' or 'l'
180 * @param k - key to translate
184 function translate($au, $type, $k)
191 $lang = !$au || empty($au->lang ) ? 'en' : is_string($au) ? $au : $au->lang;
193 // does it need caching?
195 $i = DB_DataObject::Factory('I18n');
196 return $i->translate($lang,$type,$k);