3 /// provide language data!!!
4 // THIS IS PUBLICALLY ACCESSABLE..
7 * Either we load this as a standard array at start??
10 * or we treat it like a regular pulldown... - on demand...
12 * big snag is that we can not include these until the user has specified their interface language.
14 * If we do a global jS array?
15 * Pman.Lang.en = [ 'en' , 'English']
17 * If we do a standard 'store' version..
18 * { total: x, data [ { code: 'en', title: 'English' }] }
23 * index.php/Pman/I18N/BuildDB -- buildes the database..
28 require_once 'Pman.php';
29 class Pman_I18N extends Pman
32 // these are the languages we support.
35 'en', 'zh_CN', 'zh_HK', 'zh_TW', 'th', 'ko', 'ja', 'ms',
44 'AU', 'CN', 'HK', 'IN', 'ID', 'JP', 'MY', 'NZ', 'TW', 'SG', 'TH', 'KR', 'US', 'PH', 'VN','**'
47 'USD', 'HKD', 'GBP', 'CNY', 'SGD', 'JPY'
57 parent::getAuth(); // load company!
59 $au = $this->getAuthUser();
61 // $this->jerr("Not authenticated", array('authFailure' => true));
63 $this->authUser = $au;
65 $opts = PEAR::getStaticProperty('Pman_I18N', 'options');
66 $opts = empty($opts) ? array() : $opts;
69 foreach($opts as $k=>$v) {
72 $this->cfg[$k] = $this->getDefaultCfg($k);
75 $this->cfg[$k] = explode(',', $v);
83 // returns a list of all countries..
84 function getDefaultCfg($t) {
88 require_once 'I18Nv2/Country.php';
90 $c = new I18Nv2_Country('en');
91 $ret = array_keys($c->codes);
95 require_once 'I18Nv2/Language.php';
96 $c = new I18Nv2_Language('en');
97 $ret = array_keys($c->codes);
101 require_once 'I18Nv2/Currency.php';
102 $c = new I18Nv2_Currency('en');
103 $ret = array_keys($c->codes);
107 foreach ($ret as $k=>$v) {
108 $ret[$k] = strtoupper($v);
117 function setSession($au)
119 $this->authUser = $au;
120 $lbits = implode('_', $this->findLang());
121 if (empty($_SESSION['Pman_I18N'])) {
122 $_SESSION['Pman_I18N'] = array();
125 $_SESSION['Pman_I18N'][$lbits] = array(
126 'l' => $this->getList('l', $lbits),
127 'c' => $this->getList('c', $lbits),
128 'm' => $this->getList('m', $lbits),
134 function getList($type, $inlang,$fi=false)
136 //$l = new I18Nv2_Language($inlang);
137 //$c= new I18Nv2_Country($inlang);
138 $filter = !$fi ? false : $this->loadFilter($type); // project specific languages..
146 foreach($this->cfg[$type] as $k) {
147 if (is_array($filter) && !in_array($k, $filter)) {
153 'title' => $this->translate($inlang, $type, $k)
164 function findLang() {
166 $lang = !$this->authUser || empty($this->authUser->lang ) ? 'en' : $this->authUser->lang;
167 $lbits = explode('_', strtoupper($lang));
168 $lbits[0] = strtolower($lbits[0]);
169 require_once 'I18Nv2/Country.php';
170 require_once 'I18Nv2/Language.php';
171 $langs = new I18Nv2_Language('en');
172 $countries = new I18Nv2_Country('en');
175 if (!isset($langs->codes[strtolower($lbits[0])])) {
176 $this->jerr('invalid lang');
178 if (!empty($lbits[1]) && !isset($countries->codes[$lbits[1]])) {
179 $this->jerr('invalid lang Country component');
191 $lbits = $this->findLang();
198 $ret = $this->getList('l', $lbits[0],empty($_REQUEST['filter']) ? false : $_REQUEST['filter']);
202 $ret = $this->getList('c', $lbits[0],empty($_REQUEST['filter']) ? false : $_REQUEST['filter']);
206 $ret = $this->getList('m', $lbits[0],empty($_REQUEST['filter']) ? false : $_REQUEST['filter']);
211 //DB_DataObject::debugLevel(1);
219 $this->jerr("ERROR");
226 function loadFilter($type)
228 // this code only applies to Clipping module
229 if (!$this->authUser) {
233 // this needs moving to it's own project
235 if (!$this->hasModule('Clipping')) {
242 //DB_DataObject::debugLevel(1);
243 $q = DB_DataObject::factory('Projects');
245 $c = DB_Dataobject::factory('Companies');
246 $c->get($this->authUser->company_id);
247 if ($c->comptype !='OWNER') {
248 $q->client_id = $this->authUser->company_id;
251 $col = ($type == 'l' ? 'languages' : 'countries');
252 $q->selectAdd('distinct(' . ($type == 'l' ? 'languages' : 'countries').') as dval');
253 $q->whereAdd("LENGTH($col) > 0");
257 while ($q->fetch()) {
258 $bits = explode(',', $q->dval);
259 foreach($bits as $k) {
263 return array_keys($ret);
268 function translateList($au, $type, $k)
270 $ar = explode(',', $k);
272 foreach($ar as $kk) {
273 $ret[] = $this->translate($au, $type, $kk);
275 return implode(', ', $ret);
280 * require_once 'Pman/I18N.php';
281 * $x = new Pman_I18N();
282 * $x->translate($this->authuser, 'c', 'US');
283 * @param au - auth User
284 * @param type = 'c' or 'l'
285 * @param k - key to translate
289 function translate($au, $type, $k)
296 $lang = !$au || empty($au->lang ) ? 'en' : is_string($au) ? $au : $au->lang;
297 $lbits = explode('_', strtoupper($lang));
300 if (!isset($cache[$lang])) {
301 require_once 'I18Nv2/Country.php';
302 require_once 'I18Nv2/Language.php';
303 require_once 'I18Nv2/Currency.php';
304 $cache[$lang] = array(
305 'l' => new I18Nv2_Language($lang, 'UTF-8'),
306 'c' => new I18Nv2_Country($lang, 'UTF-8'),
307 'm' => new I18Nv2_Currency($lang, 'UTF-8')
309 //echo '<PRE>';print_r(array($lang, $cache[$lang]['c']));
312 return 'Other / Unknown';
317 $tolang = explode('_', $k);
319 $ret = $cache[$lang][$type]->getName($tolang[0]);
320 if (count($tolang) > 1) {
321 $ret.= '('.$tolang[1].')';
325 $ret = $cache[$lang][$type]->getName($k);
326 //print_r(array($k, $ret));
334 function buildDB($ltype= false, $inlang= false )
336 if ($ltype === false) {
338 die("OOPS NO LTYPE");
341 if ($inlang === false) {
342 foreach( $this->cfg['l'] as $l) {
343 $this->buildDB($ltype, $l);
348 $list = $this->cfg[$ltype];
350 foreach($list as $lkey) {
351 $x = DB_DataObject::factory('i18n');
355 if ($x->find(true)) {
357 $x->lval = $this->translate($inlang, $ltype, $lkey);
361 $x->lval = $this->translate($inlang, $ltype, $lkey);