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
12 en : [ { code : 'end', title : 'English' }, .... ],
19 * index.php/Pman/I18N/BuildDB -- buildes the database..
20 * .. other formats are depreciated, but are supported by the old code....
23 * Database language translation should be done using the database table.
24 * So sorting can be done correctly..
26 * Configuration in index.php..
28 * 'Pman_Core_I18N' => array(
30 'en', 'zh_CN', 'zh_HK', 'zh_TW', 'th', 'ko', 'ja', 'ms',
38 'c' => '*', // eg. all languages..
39 'm' => array( 'USD', 'HKD', 'GBP', 'CNY', 'SGD', 'JPY' )
44 require_once 'Pman.php';
46 class Pman_Core_i18N extends Pman
50 // these are the default languages we support.
53 'en', 'zh_CN', 'zh_HK', 'zh_TW', 'th', 'ko', 'ja', 'ms',
62 'AU', 'CN', 'HK', 'IN', 'ID', 'JP', 'MY', 'NZ', 'TW', 'SG', 'TH', 'KR', 'US', 'PH', 'VN','**'
65 'USD', 'HKD', 'GBP', 'CNY', 'SGD', 'JPY'
75 parent::getAuth(); // load company!
77 $au = $this->getAuthUser();
79 // $this->jerr("Not authenticated", array('authFailure' => true));
81 $this->authUser = $au;
83 $opts = PEAR::getStaticProperty('Pman_Core_I18N', 'options');
85 $opts = PEAR::getStaticProperty('Pman_I18N', 'options');
87 $opts = empty($opts) ? array() : $opts;
89 // load the cofiguration
90 foreach($opts as $k=>$v) {
93 $this->cfg[$k] = $this->getDefaultCfg($k);
96 $this->cfg[$k] = is_array($v) ? $v : explode(',', $v);
104 // returns a list of all countries..
105 function getDefaultCfg($t) {
109 require_once 'I18Nv2/Country.php';
111 $c = new I18Nv2_Country('en');
112 $ret = array_keys($c->codes);
116 require_once 'I18Nv2/Language.php';
117 $c = new I18Nv2_Language('en');
118 $ret = array_keys($c->codes);
122 require_once 'I18Nv2/Currency.php';
123 $c = new I18Nv2_Currency('en');
124 $ret = array_keys($c->codes);
128 foreach ($ret as $k=>$v) {
129 $ret[$k] = strtoupper($v);
146 //DB_DataObject::debugLevel(1);
154 $this->outputJavascript();
155 // output javascript..
156 $this->jerr("ERROR");
167 * translate (used by database building);
169 * require_once 'Pman/Core/I18N.php';
170 * $x = new Pman_Core_I18N();
171 * $x->translate($this->authuser, 'c', 'US');
172 * @param au - auth User
173 * @param type = 'c' or 'l'
174 * @param k - key to translate
178 function translate($au, $type, $k)
185 $lang = !$au || empty($au->lang ) ? 'en' : is_string($au) ? $au : $au->lang;
186 $lbits = explode('_', strtoupper($lang));
189 if (!isset($cache[$lang])) {
190 require_once 'I18Nv2/Country.php';
191 require_once 'I18Nv2/Language.php';
192 require_once 'I18Nv2/Currency.php';
193 $cache[$lang] = array(
194 'l' => new I18Nv2_Language($lang, 'UTF-8'),
195 'c' => new I18Nv2_Country($lang, 'UTF-8'),
196 'm' => new I18Nv2_Currency($lang, 'UTF-8')
198 //echo '<PRE>';print_r(array($lang, $cache[$lang]['c']));
201 return 'Other / Unknown';
206 $tolang = explode('_', $k);
208 $ret = $cache[$lang][$type]->getName($tolang[0]);
209 if (count($tolang) > 1) {
210 $ret.= '('.$tolang[1].')';
214 $ret = $cache[$lang][$type]->getName($k);
215 //print_r(array($k, $ret));
223 function buildDB($ltype= false, $inlang= false )
225 if ($ltype === false) {
227 die("OOPS NO LTYPE");
229 if ($inlang == '**') {
230 return; // dont bother building generic..
232 if ($inlang === false) {
233 foreach( $this->cfg['l'] as $l) {
234 $this->buildDB($ltype, $l);
239 $list = $this->getDefaultCfg($ltype);
241 DB_DataObject::debugLevel(1);
243 foreach($list as $lkey) {
244 $x = DB_DataObject::factory('i18n');
248 if ($x->find(true)) {
250 $x->lval = $this->translate($inlang, $ltype, $lkey);
254 $x->lval = $this->translate($inlang, $ltype, $lkey);