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.
57 'en', 'zh_CN', 'zh_HK', 'zh_TW', 'th', 'ko', 'ja', 'ms',
66 'AU', 'CN', 'HK', 'IN', 'ID', 'JP', 'MY', 'NZ', 'TW', 'SG', 'TH', 'KR', 'US', 'PH', 'VN','**'
69 'USD', 'HKD', 'GBP', 'CNY', 'SGD', 'JPY'
79 parent::getAuth(); // load company!
81 $au = $this->getAuthUser();
83 // $this->jerr("Not authenticated", array('authFailure' => true));
85 $this->authUser = $au;
87 $opts = PEAR::getStaticProperty('Pman_Core_I18N', 'options');
89 $opts = PEAR::getStaticProperty('Pman_I18N', 'options');
91 $opts = empty($opts) ? array() : $opts;
93 // load the cofiguration
94 foreach($opts as $k=>$v) {
97 $this->cfg[$k] = $this->getDefaultCfg($k);
100 $this->cfg[$k] = is_array($v) ? $v : explode(',', $v);
108 // returns a list of all countries..
109 function getDefaultCfg($t) {
113 require_once 'I18Nv2/Country.php';
115 $c = new I18Nv2_Country('en');
116 $ret = array_keys($c->codes);
120 require_once 'I18Nv2/Language.php';
121 $c = new I18Nv2_Language('en');
122 $ret = array_keys($c->codes);
126 require_once 'I18Nv2/Currency.php';
127 $c = new I18Nv2_Currency('en');
128 $ret = array_keys($c->codes);
132 foreach ($ret as $k=>$v) {
133 $ret[$k] = strtoupper($v);
150 //DB_DataObject::debugLevel(1);
158 $this->outputJavascript();
159 // output javascript..
160 $this->jerr("ERROR");
168 function outputJavascript()
171 require_once 'I18Nv2/Country.php';
172 require_once 'I18Nv2/Language.php';
173 require_once 'I18Nv2/Currency.php';
175 $langs = $this->getDefaultCfg('l');
177 foreach($langs as $lang)
179 $lang = array_shift(explode('_', strtoupper($lang)));
182 'l' => $this->objToList(new I18Nv2_Language($lang, 'UTF-8')),
183 'c' => $this->objToList(new I18Nv2_Country($lang, 'UTF-8')),
184 'm' => $this->objToList(new I18Nv2_Currency($lang, 'UTF-8'))
187 header('Content-type: text/javascript');
188 echo 'Pman.I18n.Data = ' . json_encode($ar);
194 function objToList($obj) {
196 foreach($obj=>codes as $k=$v) {
207 * translate (used by database building);
209 * require_once 'Pman/Core/I18N.php';
210 * $x = new Pman_Core_I18N();
211 * $x->translate($this->authuser, 'c', 'US');
212 * @param au - auth User
213 * @param type = 'c' or 'l'
214 * @param k - key to translate
218 function translate($au, $type, $k)
225 $lang = !$au || empty($au->lang ) ? 'en' : is_string($au) ? $au : $au->lang;
226 $lbits = explode('_', strtoupper($lang));
229 if (!isset($cache[$lang])) {
230 require_once 'I18Nv2/Country.php';
231 require_once 'I18Nv2/Language.php';
232 require_once 'I18Nv2/Currency.php';
233 $cache[$lang] = array(
234 'l' => new I18Nv2_Language($lang, 'UTF-8'),
235 'c' => new I18Nv2_Country($lang, 'UTF-8'),
236 'm' => new I18Nv2_Currency($lang, 'UTF-8')
238 //echo '<PRE>';print_r(array($lang, $cache[$lang]['c']));
241 return 'Other / Unknown';
246 $tolang = explode('_', $k);
248 $ret = $cache[$lang][$type]->getName($tolang[0]);
249 if (count($tolang) > 1) {
250 $ret.= '('.$tolang[1].')';
254 $ret = $cache[$lang][$type]->getName($k);
255 //print_r(array($k, $ret));
263 function buildDB($ltype= false, $inlang= false )
265 if ($ltype === false) {
267 die("OOPS NO LTYPE");
269 if ($inlang == '**') {
270 return; // dont bother building generic..
272 if ($inlang === false) {
273 foreach( $this->cfg['l'] as $l) {
274 $this->buildDB($ltype, $l);
279 $list = $this->getDefaultCfg($ltype);
281 DB_DataObject::debugLevel(1);
283 foreach($list as $lkey) {
284 $x = DB_DataObject::factory('i18n');
288 if ($x->find(true)) {
290 $x->lval = $this->translate($inlang, $ltype, $lkey);
294 $x->lval = $this->translate($inlang, $ltype, $lkey);