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();
99 $opts = empty($ff->Pman_Core_I18N) ? (empty($ff->Pman_I18N) ? array() : $ff->Pman_I18N) : $ff->Pman_Core_I18N;
102 // load the cofiguration
103 foreach($opts as $k=>$v) {
106 $this->cfg[$k] = $this->getDefaultCfg($k);
109 $this->cfg[$k] = is_array($v) ? $v : explode(',', $v);
117 // returns a list of all countries..
118 function getDefaultCfg($t) {
122 require_once 'I18Nv2/Country.php';
124 $c = new I18Nv2_Country('en');
125 $ret = array_keys($c->codes);
129 require_once 'I18Nv2/Language.php';
130 $c = new I18Nv2_Language('en');
131 $ret = array_keys($c->codes);
135 require_once 'I18Nv2/Currency.php';
136 $c = new I18Nv2_Currency('en');
137 $ret = array_keys($c->codes);
142 foreach ($ret as $k=>$v) {
143 $ret[$k] = strtoupper($v);
160 //DB_DataObject::debugLevel(1);
168 $this->outputJavascript();
169 // output javascript..
170 $this->jerr("ERROR");
178 function outputJavascript()
181 require_once 'I18Nv2/Country.php';
182 require_once 'I18Nv2/Language.php';
183 require_once 'I18Nv2/Currency.php';
185 $langs = $this->cfg['t'];
186 // var_dump($langs);exit;
188 foreach($langs as $lang)
190 $rlang = array_shift(explode('_', strtoupper($lang)));
193 'l' => $this->objToList('l', new I18Nv2_Language($rlang, 'UTF-8')),
194 'c' => $this->objToList('c', new I18Nv2_Country($rlang, 'UTF-8')),
195 'm' => $this->objToList('m', new I18Nv2_Currency($rlang, 'UTF-8'))
198 //echo '<PRE>';print_r($ar);
199 header('Content-type: text/javascript');
200 echo 'Pman.I18n.Data = ' . json_encode($ar);
206 function objToList($type, $obj) {
210 foreach($this->cfg[$type] as $k) {
213 if (strpos($k, '_') !== false) {
214 $bits = explode('_', $k);
215 $k = array_shift($bits);
216 $sub = array_shift($bits);
218 $v = $k == '**' ? 'Other' : $obj->getName($k);
225 'code'=> ($type=='l' ? strtolower($k) : strtoupper($k)) . ($sub ? '_'.strtoupper($sub) : ''),
233 * translate (used by database building);
235 * require_once 'Pman/Core/I18N.php';
236 * $x = new Pman_Core_I18N();
237 * $x->translate($this->authuser, 'c', 'US');
238 * @param au - auth User
239 * @param type = 'c' or 'l'
240 * @param k - key to translate
244 function translate($au, $type, $k)
251 $lang = !$au || empty($au->lang ) ? 'en' : is_string($au) ? $au : $au->lang;
252 $lbits = explode('_', strtoupper($lang));
255 if (!isset($cache[$lang])) {
256 require_once 'I18Nv2/Country.php';
257 require_once 'I18Nv2/Language.php';
258 require_once 'I18Nv2/Currency.php';
259 $cache[$lang] = array(
260 'l' => new I18Nv2_Language($lang, 'UTF-8'),
261 'c' => new I18Nv2_Country($lang, 'UTF-8'),
262 'm' => new I18Nv2_Currency($lang, 'UTF-8')
264 //echo '<PRE>';print_r(array($lang, $cache[$lang]['c']));
267 return 'Other / Unknown';
272 $tolang = explode('_', $k);
274 $ret = $cache[$lang][$type]->getName($tolang[0]);
275 if (count($tolang) > 1) {
276 $ret.= '('.$tolang[1].')';
280 $ret = $cache[$lang][$type]->getName($k);
281 //print_r(array($k, $ret));
289 function buildDB($ltype= false, $inlang= false )
291 if ($ltype === false) {
293 die("OOPS NO LTYPE");
295 if ($inlang == '**') {
296 return; // dont bother building generic..
298 if ($inlang === false) {
299 foreach( $this->cfg['t'] as $l) {
300 $this->buildDB($ltype, $l);
305 $list = $this->getDefaultCfg($ltype);
307 DB_DataObject::debugLevel(1);
309 foreach($list as $lkey) {
310 $x = DB_DataObject::factory('i18n');
314 if ($x->find(true)) {
316 $x->lval = $this->translate($inlang, $ltype, $lkey);
320 $x->lval = $this->translate($inlang, $ltype, $lkey);