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'
57 * initalizie the cfg aray
62 static $loaded = false;
67 $ff= HTML_FlexyFramework::get();
69 // since our opts array changed alot..
70 $opts = empty($ff->Pman_Core_I18N) ? (empty($ff->Pman_I18N) ? array() : $ff->Pman_I18N) : $ff->Pman_Core_I18N;
72 $i = DB_DataObject::Factory('I18n');
73 // load the cofiguration
74 foreach($opts as $k=>$v) {
76 if ($v == '*') { // everything..
77 self::$cfg[$k] = $i->availableCodes($k);
80 self::$cfg[$k] = is_array($v) ? $v : explode(',', $v);
88 // the default configuration.
90 function applyFilters($q, $au)
93 //DB_DataObject::debugLevel(1);
94 if (!empty($q['query']['_with_en'])) {
96 $this->buildDB(); // ensure we have the full database...
99 i18n_translate(ltype, lkey, 'en') as lval_en
106 function translate($inlang,$ltype,$kval)
109 $x = DB_DataObject::factory('i18n');
121 function toTransList($ltype, $inlang)
124 $x = DB_DataObject::factory('i18n');
128 $x->selectAdd('lkey as code, lval as title');
131 while ($x->fetch()) {
134 'title' =>$x->title);
142 // -------------- code to handle importing into database..
147 // returns a list of all countries/languages etc.. (with '*')
148 function availableCodes($t)
153 require_once 'I18Nv2/Country.php';
155 $c = new I18Nv2_Country('en');
156 $ret = array_keys($c->codes);
160 require_once 'I18Nv2/Language.php';
161 $c = new I18Nv2_Language('en');
162 $ret = array_keys($c->codes);
166 require_once 'I18Nv2/Currency.php';
167 $c = new I18Nv2_Currency('en');
168 $ret = array_keys($c->codes);
173 foreach ($ret as $k=>$v) {
174 $ret[$k] = strtoupper($v);
182 function buildDB($ltype= false, $inlang= false )
185 if ($ltype === false) {
186 // trigger all builds.
187 //DB_DataObject::debugLevel(1);
193 if ($inlang == '**') {
194 return; // dont bother building generic..
198 if ($inlang === false) {
199 // do we want to add our 'configured ones..'
200 // We only build translatiosn for our configured ones..
201 //foreach( $this->availableCodes('l') as $l) {
203 foreach( self::$cfg['t'] as $l) {
204 $this->buildDB($ltype, $l);
210 //DB_DataObject::debugLevel(1);
211 $x = DB_DataObject::factory('i18n');
215 $complete = $x->fetchAll('lkey');
217 $list = $this->availableCodes($ltype);
220 foreach($list as $lkey) {
221 // skip ones we know we have done...
222 if (in_array($lkey, $complete)) {
225 $x = DB_DataObject::factory('i18n');
229 if ($x->find(true)) {
231 $x->lval = $this->defaultTranslate($inlang, $ltype, $lkey);
235 $x->lval = $this->defaultTranslate($inlang, $ltype, $lkey);
244 * default translate - use i18n classes to provide a value.
249 function defaultTranslate($lang, $type, $k)
258 $lbits = explode('_', strtoupper($lang));
261 if (!isset($cache[$lang])) {
262 require_once 'I18Nv2/Country.php';
263 require_once 'I18Nv2/Language.php';
264 require_once 'I18Nv2/Currency.php';
265 $cache[$lang] = array(
266 'l' => new I18Nv2_Language($lang, 'UTF-8'),
267 'c' => new I18Nv2_Country($lang, 'UTF-8'),
268 'm' => new I18Nv2_Currency($lang, 'UTF-8')
270 //echo '<PRE>';print_r(array($lang, $cache[$lang]['c']));
274 return 'Other / Unknown';
279 $tolang = explode('_', $k);
281 $ret = $cache[$lang][$type]->getName($tolang[0]);
282 if (count($tolang) > 1) {
283 $ret.= '('.$tolang[1].')';
287 $ret = $cache[$lang][$type]->getName($k);
288 //print_r(array($k, $ret));