3 /// provide language data!!!
4 // DEPRECIATED - moved to Pman_I18N
10 require_once 'Pman/Core/I18N.php';
11 class Pman_I18N extends Pman_Core_I18N
14 // these are the languages we support.
17 'en', 'zh_CN', 'zh_HK', 'zh_TW', 'th', 'ko', 'ja', 'ms',
26 'AU', 'CN', 'HK', 'IN', 'ID', 'JP', 'MY', 'NZ', 'TW', 'SG', 'TH', 'KR', 'US', 'PH', 'VN','**'
29 'USD', 'HKD', 'GBP', 'CNY', 'SGD', 'JPY'
39 parent::getAuth(); // load company!
41 $au = $this->getAuthUser();
43 // $this->jerr("Not authenticated", array('authFailure' => true));
45 $this->authUser = $au;
47 $opts = PEAR::getStaticProperty('Pman_I18N', 'options');
48 $opts = empty($opts) ? array() : $opts;
51 foreach($opts as $k=>$v) {
54 $this->cfg[$k] = $this->getDefaultCfg($k);
57 $this->cfg[$k] = is_array($v) ? $v : explode(',', $v);
65 // returns a list of all countries..
66 function getDefaultCfg($t) {
70 require_once 'I18Nv2/Country.php';
72 $c = new I18Nv2_Country('en');
73 $ret = array_keys($c->codes);
77 require_once 'I18Nv2/Language.php';
78 $c = new I18Nv2_Language('en');
79 $ret = array_keys($c->codes);
83 require_once 'I18Nv2/Currency.php';
84 $c = new I18Nv2_Currency('en');
85 $ret = array_keys($c->codes);
89 foreach ($ret as $k=>$v) {
90 $ret[$k] = strtoupper($v);
99 function setSession($au)
101 $this->authUser = $au;
102 $lbits = implode('_', $this->findLang());
103 if (empty($_SESSION['Pman_I18N'])) {
104 $_SESSION['Pman_I18N'] = array();
107 $_SESSION['Pman_I18N'][$lbits] = array(
108 'l' => $this->getList('l', $lbits),
109 'c' => $this->getList('c', $lbits),
110 'm' => $this->getList('m', $lbits),
116 function getList($type, $inlang,$fi=false)
118 //$l = new I18Nv2_Language($inlang);
119 //$c= new I18Nv2_Country($inlang);
120 $filter = !$fi ? false : $this->loadFilter($type); // project specific languages..
128 foreach($this->cfg[$type] as $k) {
129 if (is_array($filter) && !in_array($k, $filter)) {
135 'title' => $this->translate($inlang, $type, $k)
146 function findLang() {
148 $lang = !$this->authUser || empty($this->authUser->lang ) ? 'en' : $this->authUser->lang;
149 $lbits = explode('_', strtoupper($lang));
150 $lbits[0] = strtolower($lbits[0]);
151 require_once 'I18Nv2/Country.php';
152 require_once 'I18Nv2/Language.php';
153 $langs = new I18Nv2_Language('en');
154 $countries = new I18Nv2_Country('en');
157 if (!isset($langs->codes[strtolower($lbits[0])])) {
158 $this->jerr('invalid lang');
160 if (!empty($lbits[1]) && !isset($countries->codes[$lbits[1]])) {
161 $this->jerr('invalid lang Country component');
173 $lbits = $this->findLang();
180 $ret = $this->getList('l', $lbits[0],empty($_REQUEST['filter']) ? false : $_REQUEST['filter']);
184 $ret = $this->getList('c', $lbits[0],empty($_REQUEST['filter']) ? false : $_REQUEST['filter']);
188 $ret = $this->getList('m', $lbits[0],empty($_REQUEST['filter']) ? false : $_REQUEST['filter']);
190 // part of parent!!!!
194 //DB_DataObject::debugLevel(1);
202 $this->jerr("ERROR");
209 function loadFilter($type)
211 // this code only applies to Clipping module
212 if (!$this->authUser) {
216 // this needs moving to it's own project
218 if (!$this->hasModule('Clipping')) {
225 //DB_DataObject::debugLevel(1);
226 $q = DB_DataObject::factory('Projects');
228 $c = DB_Dataobject::factory('Companies');
229 $c->get($this->authUser->company_id);
230 if ($c->comptype !='OWNER') {
231 $q->client_id = $this->authUser->company_id;
234 $col = ($type == 'l' ? 'languages' : 'countries');
235 $q->selectAdd('distinct(' . ($type == 'l' ? 'languages' : 'countries').') as dval');
236 $q->whereAdd("LENGTH($col) > 0");
240 while ($q->fetch()) {
241 $bits = explode(',', $q->dval);
242 foreach($bits as $k) {
246 return array_keys($ret);
251 function translateList($au, $type, $k)
253 $ar = explode(',', $k);
255 foreach($ar as $kk) {
256 $ret[] = $this->translate($au, $type, $kk);
258 return implode(', ', $ret);
263 * require_once 'Pman/I18N.php';
264 * $x = new Pman_I18N();
265 * $x->translate($this->authuser, 'c', 'US');
266 * @param au - auth User
267 * @param type = 'c' or 'l'
268 * @param k - key to translate
272 function translate($au, $type, $k)
279 $lang = !$au || empty($au->lang ) ? 'en' : is_string($au) ? $au : $au->lang;
280 $lbits = explode('_', strtoupper($lang));
283 if (!isset($cache[$lang])) {
284 require_once 'I18Nv2/Country.php';
285 require_once 'I18Nv2/Language.php';
286 require_once 'I18Nv2/Currency.php';
287 $cache[$lang] = array(
288 'l' => new I18Nv2_Language($lang, 'UTF-8'),
289 'c' => new I18Nv2_Country($lang, 'UTF-8'),
290 'm' => new I18Nv2_Currency($lang, 'UTF-8')
292 //echo '<PRE>';print_r(array($lang, $cache[$lang]['c']));
295 return 'Other / Unknown';
300 $tolang = explode('_', $k);
302 $ret = $cache[$lang][$type]->getName($tolang[0]);
303 if (count($tolang) > 1) {
304 $ret.= '('.$tolang[1].')';
308 $ret = $cache[$lang][$type]->getName($k);
309 //print_r(array($k, $ret));