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)
58 'en', 'zh_CN', 'zh_HK', 'zh_TW', 'th', 'ko', 'ja', 'ms',
67 'AU', 'CN', 'HK', 'IN', 'ID', 'JP', 'MY', 'NZ', 'TW', 'SG', 'TH', 'KR', 'US', 'PH', 'VN','**'
70 'USD', 'HKD', 'GBP', 'CNY', 'SGD', 'JPY'
80 parent::getAuth(); // load company!
82 $au = $this->getAuthUser();
84 // $this->jerr("Not authenticated", array('authFailure' => true));
86 $this->authUser = $au;
88 $opts = PEAR::getStaticProperty('Pman_Core_I18N', 'options');
90 $opts = PEAR::getStaticProperty('Pman_I18N', 'options');
92 $opts = empty($opts) ? array() : $opts;
94 // load the cofiguration
95 foreach($opts as $k=>$v) {
98 $this->cfg[$k] = $this->getDefaultCfg($k);
101 $this->cfg[$k] = is_array($v) ? $v : explode(',', $v);
109 // returns a list of all countries..
110 function getDefaultCfg($t) {
114 require_once 'I18Nv2/Country.php';
116 $c = new I18Nv2_Country('en');
117 $ret = array_keys($c->codes);
121 require_once 'I18Nv2/Language.php';
122 $c = new I18Nv2_Language('en');
123 $ret = array_keys($c->codes);
127 require_once 'I18Nv2/Currency.php';
128 $c = new I18Nv2_Currency('en');
129 $ret = array_keys($c->codes);
133 foreach ($ret as $k=>$v) {
134 $ret[$k] = strtoupper($v);
151 //DB_DataObject::debugLevel(1);
159 $this->outputJavascript();
160 // output javascript..
161 $this->jerr("ERROR");
169 function outputJavascript()
172 require_once 'I18Nv2/Country.php';
173 require_once 'I18Nv2/Language.php';
174 require_once 'I18Nv2/Currency.php';
176 $langs = $this->cfg['l'];
178 foreach($langs as $lang)
180 $lang = array_shift(explode('_', strtoupper($lang)));
183 'l' => $this->objToList(new I18Nv2_Language($lang, 'UTF-8')),
184 'c' => $this->objToList(new I18Nv2_Country($lang, 'UTF-8')),
185 'm' => $this->objToList(new I18Nv2_Currency($lang, 'UTF-8'))
188 header('Content-type: text/javascript');
189 echo 'Pman.I18n.Data = ' . json_encode($ar);
195 function objToList($obj) {
197 foreach($obj->codes as $k=>$v) {
208 * translate (used by database building);
210 * require_once 'Pman/Core/I18N.php';
211 * $x = new Pman_Core_I18N();
212 * $x->translate($this->authuser, 'c', 'US');
213 * @param au - auth User
214 * @param type = 'c' or 'l'
215 * @param k - key to translate
219 function translate($au, $type, $k)
226 $lang = !$au || empty($au->lang ) ? 'en' : is_string($au) ? $au : $au->lang;
227 $lbits = explode('_', strtoupper($lang));
230 if (!isset($cache[$lang])) {
231 require_once 'I18Nv2/Country.php';
232 require_once 'I18Nv2/Language.php';
233 require_once 'I18Nv2/Currency.php';
234 $cache[$lang] = array(
235 'l' => new I18Nv2_Language($lang, 'UTF-8'),
236 'c' => new I18Nv2_Country($lang, 'UTF-8'),
237 'm' => new I18Nv2_Currency($lang, 'UTF-8')
239 //echo '<PRE>';print_r(array($lang, $cache[$lang]['c']));
242 return 'Other / Unknown';
247 $tolang = explode('_', $k);
249 $ret = $cache[$lang][$type]->getName($tolang[0]);
250 if (count($tolang) > 1) {
251 $ret.= '('.$tolang[1].')';
255 $ret = $cache[$lang][$type]->getName($k);
256 //print_r(array($k, $ret));
264 function buildDB($ltype= false, $inlang= false )
266 if ($ltype === false) {
268 die("OOPS NO LTYPE");
270 if ($inlang == '**') {
271 return; // dont bother building generic..
273 if ($inlang === false) {
274 foreach( $this->cfg['l'] as $l) {
275 $this->buildDB($ltype, $l);
280 $list = $this->getDefaultCfg($ltype);
282 DB_DataObject::debugLevel(1);
284 foreach($list as $lkey) {
285 $x = DB_DataObject::factory('i18n');
289 if ($x->find(true)) {
291 $x->lval = $this->translate($inlang, $ltype, $lkey);
295 $x->lval = $this->translate($inlang, $ltype, $lkey);