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;
101 $i = DB_DataObject::Factory('I18n');
102 // load the cofiguration
103 foreach($opts as $k=>$v) {
105 if ($v == '*') { // everything..
106 $this->cfg[$k] = $i->availableCodes($k);
109 $this->cfg[$k] = is_array($v) ? $v : explode(',', $v);
123 $i = DB_DataObject::Factory('I18n');
125 $this->outputJavascript();
132 function outputJavascript()
135 $i = DB_DataObject::Factory('I18n');
137 $langs = $this->cfg['t'];
138 // var_dump($langs);exit;
140 foreach($langs as $lang)
142 $rlang = array_shift(explode('_', strtoupper($lang)));
145 'l' => $i->toTransList('l', $rlang),
146 'c' => $i->toTransList('c', $rlang),
147 'm' => $i->toTransList('m', $rlang),
150 //echo '<PRE>';print_r($ar);
151 header('Content-type: text/javascript');
152 echo 'Pman.I18n.Data = ' . json_encode($ar);
162 * translate (used by database building);
164 * require_once 'Pman/Core/I18N.php';
165 * $x = new Pman_Core_I18N();
166 * $x->translate($this->authuser, 'c', 'US');
167 * @param au - auth User
168 * @param type = 'c' or 'l'
169 * @param k - key to translate
173 function translate($au, $type, $k)
180 $lang = !$au || empty($au->lang ) ? 'en' : is_string($au) ? $au : $au->lang;
182 // does it need caching?
184 $i = DB_DataObject::Factory('I18n');
185 return $i->translate($lang,$type,$k);
190 $lbits = explode('_', strtoupper($lang));
196 if (!isset($cache[$lang])) {
197 require_once 'I18Nv2/Country.php';
198 require_once 'I18Nv2/Language.php';
199 require_once 'I18Nv2/Currency.php';
200 $cache[$lang] = array(
201 'l' => new I18Nv2_Language($lang, 'UTF-8'),
202 'c' => new I18Nv2_Country($lang, 'UTF-8'),
203 'm' => new I18Nv2_Currency($lang, 'UTF-8')
205 //echo '<PRE>';print_r(array($lang, $cache[$lang]['c']));
208 return 'Other / Unknown';
213 $tolang = explode('_', $k);
215 $ret = $cache[$lang][$type]->getName($tolang[0]);
216 if (count($tolang) > 1) {
217 $ret.= '('.$tolang[1].')';
221 $ret = $cache[$lang][$type]->getName($k);
222 //print_r(array($k, $ret));