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)
57 // translated versions availalable
59 'en', 'zh_CN', 'zh_HK',
61 // languages available
63 'en', 'zh_CN', 'zh_HK', 'zh_TW', 'th', 'ko', 'ja', 'ms',
72 'AU', 'CN', 'HK', 'IN', 'ID', 'JP', 'MY', 'NZ', 'TW', 'SG', 'TH', 'KR', 'US', 'PH', 'VN','**'
75 'USD', 'HKD', 'GBP', 'CNY', 'SGD', 'JPY'
85 parent::getAuth(); // load company!
87 $au = $this->getAuthUser();
89 // $this->jerr("Not authenticated", array('authFailure' => true));
91 $this->authUser = $au;
93 $opts = PEAR::getStaticProperty('Pman_Core_I18N', 'options');
95 $opts = PEAR::getStaticProperty('Pman_I18N', 'options');
97 $opts = empty($opts) ? array() : $opts;
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);
138 foreach ($ret as $k=>$v) {
139 $ret[$k] = strtoupper($v);
156 //DB_DataObject::debugLevel(1);
164 $this->outputJavascript();
165 // output javascript..
166 $this->jerr("ERROR");
174 function outputJavascript()
177 require_once 'I18Nv2/Country.php';
178 require_once 'I18Nv2/Language.php';
179 require_once 'I18Nv2/Currency.php';
181 $langs = $this->cfg['l'];
182 var_dump($langs);exit;
184 foreach($langs as $lang)
186 $lang = array_shift(explode('_', strtoupper($lang)));
189 'l' => $this->objToList(new I18Nv2_Language($lang, 'UTF-8')),
190 'c' => $this->objToList(new I18Nv2_Country($lang, 'UTF-8')),
191 'm' => $this->objToList(new I18Nv2_Currency($lang, 'UTF-8'))
194 header('Content-type: text/javascript');
195 echo 'Pman.I18n.Data = ' . json_encode($ar);
201 function objToList($obj) {
203 foreach($obj->codes as $k=>$v) {
214 * translate (used by database building);
216 * require_once 'Pman/Core/I18N.php';
217 * $x = new Pman_Core_I18N();
218 * $x->translate($this->authuser, 'c', 'US');
219 * @param au - auth User
220 * @param type = 'c' or 'l'
221 * @param k - key to translate
225 function translate($au, $type, $k)
232 $lang = !$au || empty($au->lang ) ? 'en' : is_string($au) ? $au : $au->lang;
233 $lbits = explode('_', strtoupper($lang));
236 if (!isset($cache[$lang])) {
237 require_once 'I18Nv2/Country.php';
238 require_once 'I18Nv2/Language.php';
239 require_once 'I18Nv2/Currency.php';
240 $cache[$lang] = array(
241 'l' => new I18Nv2_Language($lang, 'UTF-8'),
242 'c' => new I18Nv2_Country($lang, 'UTF-8'),
243 'm' => new I18Nv2_Currency($lang, 'UTF-8')
245 //echo '<PRE>';print_r(array($lang, $cache[$lang]['c']));
248 return 'Other / Unknown';
253 $tolang = explode('_', $k);
255 $ret = $cache[$lang][$type]->getName($tolang[0]);
256 if (count($tolang) > 1) {
257 $ret.= '('.$tolang[1].')';
261 $ret = $cache[$lang][$type]->getName($k);
262 //print_r(array($k, $ret));
270 function buildDB($ltype= false, $inlang= false )
272 if ($ltype === false) {
274 die("OOPS NO LTYPE");
276 if ($inlang == '**') {
277 return; // dont bother building generic..
279 if ($inlang === false) {
280 foreach( $this->cfg['t'] as $l) {
281 $this->buildDB($ltype, $l);
286 $list = $this->getDefaultCfg($ltype);
288 DB_DataObject::debugLevel(1);
290 foreach($list as $lkey) {
291 $x = DB_DataObject::factory('i18n');
295 if ($x->find(true)) {
297 $x->lval = $this->translate($inlang, $ltype, $lkey);
301 $x->lval = $this->translate($inlang, $ltype, $lkey);