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
54 // these are the default languages we support.
55 // they will allways be overlaid with the current configuration (via getAuth)
56 // THESE WILL ALLWAYS BE UPPERCASE!!!
58 // translated versions availalable
61 'en', 'zh_CN', 'zh_HK',
63 // languages available
66 'en', 'zh_CN', 'zh_HK', 'zh_TW', 'th', 'ko', 'ja', 'ms',
75 'AU', 'CN', 'HK', 'IN', 'ID', 'JP', 'MY', 'NZ', 'TW', 'SG', 'TH', 'KR', 'US', 'PH', 'VN','**'
78 'USD', 'HKD', 'GBP', 'CNY', 'SGD', 'JPY'
88 parent::getAuth(); // load company!
90 $au = $this->getAuthUser();
92 // $this->jerr("Not authenticated", array('authFailure' => true));
94 $this->authUser = $au;
96 $ff= HTML_FlexyFramework::get();
97 $opts = empty($ff->Pman_Core_I18N) ? (empty($ff->Pman_I18N) ? array() : $ff->Pman_I18N) : $ff->Pman_Core_I18N;
99 // load the cofiguration
100 foreach($opts as $k=>$v) {
103 $this->cfg[$k] = $this->getDefaultCfg($k);
106 $this->cfg[$k] = is_array($v) ? $v : explode(',', $v);
114 // returns a list of all countries..
115 function getDefaultCfg($t) {
119 require_once 'I18Nv2/Country.php';
121 $c = new I18Nv2_Country('en');
122 $ret = array_keys($c->codes);
126 require_once 'I18Nv2/Language.php';
127 $c = new I18Nv2_Language('en');
128 $ret = array_keys($c->codes);
132 require_once 'I18Nv2/Currency.php';
133 $c = new I18Nv2_Currency('en');
134 $ret = array_keys($c->codes);
139 foreach ($ret as $k=>$v) {
140 $ret[$k] = strtoupper($v);
157 //DB_DataObject::debugLevel(1);
165 $this->outputJavascript();
166 // output javascript..
167 $this->jerr("ERROR");
175 function outputJavascript()
178 require_once 'I18Nv2/Country.php';
179 require_once 'I18Nv2/Language.php';
180 require_once 'I18Nv2/Currency.php';
182 $langs = $this->cfg['t'];
183 // var_dump($langs);exit;
185 foreach($langs as $lang)
187 $rlang = array_shift(explode('_', strtoupper($lang)));
190 'l' => $this->objToList('l', new I18Nv2_Language($rlang, 'UTF-8')),
191 'c' => $this->objToList('c', new I18Nv2_Country($rlang, 'UTF-8')),
192 'm' => $this->objToList('m', new I18Nv2_Currency($rlang, 'UTF-8'))
195 //echo '<PRE>';print_r($ar);
196 header('Content-type: text/javascript');
197 echo 'Pman.I18n.Data = ' . json_encode($ar);
203 function objToList($type, $obj) {
205 echo '<PRE>';print_r($this->cfg);
208 foreach($this->cfg[$type] as $k) {
210 if (strpos($k, '_') !== false) {
211 $bits = explode('_', $k);
212 $k = array_shift($bits);
213 $sub = array_shift($bits);
215 $v = $k == '**' ? 'Other' : $obj->getName($k);
222 'code'=> $type=='l' ? strtolower($k) : strtoupper($k),
230 * translate (used by database building);
232 * require_once 'Pman/Core/I18N.php';
233 * $x = new Pman_Core_I18N();
234 * $x->translate($this->authuser, 'c', 'US');
235 * @param au - auth User
236 * @param type = 'c' or 'l'
237 * @param k - key to translate
241 function translate($au, $type, $k)
248 $lang = !$au || empty($au->lang ) ? 'en' : is_string($au) ? $au : $au->lang;
249 $lbits = explode('_', strtoupper($lang));
252 if (!isset($cache[$lang])) {
253 require_once 'I18Nv2/Country.php';
254 require_once 'I18Nv2/Language.php';
255 require_once 'I18Nv2/Currency.php';
256 $cache[$lang] = array(
257 'l' => new I18Nv2_Language($lang, 'UTF-8'),
258 'c' => new I18Nv2_Country($lang, 'UTF-8'),
259 'm' => new I18Nv2_Currency($lang, 'UTF-8')
261 //echo '<PRE>';print_r(array($lang, $cache[$lang]['c']));
264 return 'Other / Unknown';
269 $tolang = explode('_', $k);
271 $ret = $cache[$lang][$type]->getName($tolang[0]);
272 if (count($tolang) > 1) {
273 $ret.= '('.$tolang[1].')';
277 $ret = $cache[$lang][$type]->getName($k);
278 //print_r(array($k, $ret));
286 function buildDB($ltype= false, $inlang= false )
288 if ($ltype === false) {
290 die("OOPS NO LTYPE");
292 if ($inlang == '**') {
293 return; // dont bother building generic..
295 if ($inlang === false) {
296 foreach( $this->cfg['t'] as $l) {
297 $this->buildDB($ltype, $l);
302 $list = $this->getDefaultCfg($ltype);
304 DB_DataObject::debugLevel(1);
306 foreach($list as $lkey) {
307 $x = DB_DataObject::factory('i18n');
311 if ($x->find(true)) {
313 $x->lval = $this->translate($inlang, $ltype, $lkey);
317 $x->lval = $this->translate($inlang, $ltype, $lkey);