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
61 parent::getAuth(); // load company!
63 $au = $this->getAuthUser();
65 // $this->jerr("Not authenticated", array('authFailure' => true));
67 $this->authUser = $au;
69 $ff= HTML_FlexyFramework::get();
72 $opts = empty($ff->Pman_Core_I18N) ? (empty($ff->Pman_I18N) ? array() : $ff->Pman_I18N) : $ff->Pman_Core_I18N;
74 $i = DB_DataObject::Factory('I18n');
83 function guessUsersLanguage() {
85 $lang = !$this->authUser || empty($this->authUser->lang ) ? 'en' : $this->authUser->lang;
86 $lbits = explode('_', strtoupper($lang));
87 $lbits[0] = strtolower($lbits[0]);
89 /// verify the selected language..
92 require_once 'I18Nv2/Country.php';
93 require_once 'I18Nv2/Language.php';
94 $langs = new I18Nv2_Language('en');
95 $countries = new I18Nv2_Country('en');
98 if (!isset($langs->codes[strtolower($lbits[0])])) {
99 $this->jerr('invalid lang');
101 if (!empty($lbits[1]) && !isset($countries->codes[$lbits[1]])) {
102 $this->jerr('invalid lang Country component');
111 $lbits = $this->guessUsersLanguage();
118 $ret = $this->getList('l', $lbits[0],empty($_REQUEST['filter']) ? false : $_REQUEST['filter']);
122 $ret = $this->getList('c', $lbits[0],empty($_REQUEST['filter']) ? false : $_REQUEST['filter']);
126 $ret = $this->getList('m', $lbits[0],empty($_REQUEST['filter']) ? false : $_REQUEST['filter']);
128 // part of parent!!!!
132 //DB_DataObject::debugLevel(1);
143 $i = DB_DataObject::Factory('I18n');
147 $i = DB_DataObject::Factory('I18n');
150 // var_dump($langs);exit;
152 foreach($langs as $lang)
154 $rlang = array_shift(explode('_', strtoupper($lang)));
157 'l' => $i->toTransList('l', $rlang),
158 'c' => $i->toTransList('c', $rlang),
159 'm' => $i->toTransList('m', $rlang),
162 //echo '<PRE>';print_r($ar);
163 header('Content-type: text/javascript');
164 echo 'Pman.I18n.Data = ' . json_encode($ar);
174 * translate (used by database building);
176 * require_once 'Pman/Core/I18N.php';
177 * $x = new Pman_Core_I18N();
178 * $x->translate($this->authuser, 'c', 'US');
179 * @param au - auth User
180 * @param type = 'c' or 'l'
181 * @param k - key to translate
185 function translate($au, $type, $k)
192 $lang = !$au || empty($au->lang ) ? 'en' : is_string($au) ? $au : $au->lang;
194 // does it need caching?
196 $i = DB_DataObject::Factory('I18n');
197 return $i->translate($lang,$type,$k);