3 * Table Definition for i18n
5 * This is heavily related to the Pman_I18n implementation..
7 * It should eventually replace most of that..
10 require_once 'DB/DataObject.php';
12 class Pman_Core_DataObjects_I18n extends DB_DataObject
15 /* the code below is auto generated do not remove the above tag */
17 public $__table = 'i18n'; // table name
18 public $id; // int(11) not_null primary_key auto_increment
19 public $ltype; // string(1) not_null multiple_key
20 public $lkey; // string(8) not_null
21 public $inlang; // string(8) not_null
22 public $lval; // string(64) not_null
25 /* the code above is auto generated do not remove the tag below */
28 // we have a small default set of languages available..
29 // you can modify this by making this setting in the index.php loader.
30 // Pman_Core_i18n = array( 'c' => *, 'l' => '*', 'm' => '*')
33 // translated versions availalable
36 'en', 'zh_CN', 'zh_HK',
38 // languages available
41 'en', 'zh_CN', 'zh_HK', 'zh_TW', 'th', 'ko', 'ja', 'ms',
50 'AU', 'CN', 'HK', 'IN', 'ID', 'JP', 'MY', 'NZ', 'TW', 'SG', 'TH', 'KR', 'US', 'PH', 'VN','**'
53 'USD', 'HKD', 'GBP', 'CNY', 'SGD', 'JPY'
58 // the default configuration.
60 function applyFilters($q, $au)
63 //DB_DataObject::debugLevel(1);
64 if (!empty($q['query']['_with_en'])) {
66 i18n_translate(ltype, lkey, 'en') as lval_en
72 // returns a list of all countries/languages etc.. (with '*')
73 function availableCodes($t)
78 require_once 'I18Nv2/Country.php';
80 $c = new I18Nv2_Country('en');
81 $ret = array_keys($c->codes);
85 require_once 'I18Nv2/Language.php';
86 $c = new I18Nv2_Language('en');
87 $ret = array_keys($c->codes);
91 require_once 'I18Nv2/Currency.php';
92 $c = new I18Nv2_Currency('en');
93 $ret = array_keys($c->codes);
98 foreach ($ret as $k=>$v) {
99 $ret[$k] = strtoupper($v);
107 function buildDB($ltype= false, $inlang= false )
109 if ($ltype === false) {
110 die("OOPS NO LTYPE");
112 if ($inlang == '**') {
113 return; // dont bother building generic..
117 if ($inlang === false) {
118 // do we want to add our 'configured ones..'
119 foreach( $this->availableCodes('l') as $l) {
121 // foreach( $this->cfg['t'] as $l) {
122 $this->buildDB($ltype, $l);
127 $list = $this->availableCodes($ltype);
129 //DB_DataObject::debugLevel(1);
131 foreach($list as $lkey) {
132 $x = DB_DataObject::factory('i18n');
136 if ($x->find(true)) {
138 $x->lval = $this->defaultTranslate($inlang, $ltype, $lkey);
142 $x->lval = $this->defaultTranslate($inlang, $ltype, $lkey);
151 * default translate - use i18n classes to provide a value.
156 function defaultTranslate($lang, $type, $k)
165 $lbits = explode('_', strtoupper($lang));
168 if (!isset($cache[$lang])) {
169 require_once 'I18Nv2/Country.php';
170 require_once 'I18Nv2/Language.php';
171 require_once 'I18Nv2/Currency.php';
172 $cache[$lang] = array(
173 'l' => new I18Nv2_Language($lang, 'UTF-8'),
174 'c' => new I18Nv2_Country($lang, 'UTF-8'),
175 'm' => new I18Nv2_Currency($lang, 'UTF-8')
177 //echo '<PRE>';print_r(array($lang, $cache[$lang]['c']));
181 return 'Other / Unknown';
186 $tolang = explode('_', $k);
188 $ret = $cache[$lang][$type]->getName($tolang[0]);
189 if (count($tolang) > 1) {
190 $ret.= '('.$tolang[1].')';
194 $ret = $cache[$lang][$type]->getName($k);
195 //print_r(array($k, $ret));