I18n.php
[Pman.Core] / I18n.php
index 3d616c8..773a081 100644 (file)
--- a/I18n.php
+++ b/I18n.php
  */
 require_once 'Pman.php';
 
-class Pman_Core_i18N extends Pman
+class Pman_Core_I18N extends Pman
 {
  
     
     // these are the default languages we support.
     // they will allways be overlaid with the current configuration (via getAuth)
+    // THESE WILL ALLWAYS BE UPPERCASE!!!
     var $cfg = array(
         // translated versions availalable
+        
         't' => array(
             'en', 'zh_CN',   'zh_HK', 
         ),
         // languages available
         'l' => array(
+            
             'en', 'zh_CN',   'zh_HK',  'zh_TW', 'th', 'ko', 'ja', 'ms', 
             'id', // indonesian
             'tl', // tagalog
@@ -90,17 +93,17 @@ class Pman_Core_i18N extends Pman
         //}
         $this->authUser = $au;
         
-        $opts = PEAR::getStaticProperty('Pman_Core_I18N', 'options');
-        if (empty($opts)) {
-            $opts = PEAR::getStaticProperty('Pman_I18N', 'options');
-        }
-        $opts = empty($opts)  ?  array() : $opts;
+        $ff= HTML_FlexyFramework::get();
+         
         
+        $opts = empty($ff->Pman_Core_I18N) ? (empty($ff->Pman_I18N) ? array() : $ff->Pman_I18N)  : $ff->Pman_Core_I18N;
+        
+        $i = DB_DataObject::Factory('I18n');
         // load the cofiguration
         foreach($opts as $k=>$v) {
             
-            if ($v == '*') {
-                $this->cfg[$k] = $this->getDefaultCfg($k);
+            if ($v == '*') { // everything..
+                $this->cfg[$k] = $i->availableCodes($k);
                 continue;
             }
             $this->cfg[$k] = is_array($v) ? $v  : explode(',', $v);
@@ -111,62 +114,17 @@ class Pman_Core_i18N extends Pman
         
         return true;
     }
-    // returns a list of all countries..
-    function getDefaultCfg($t) {
-        $ret = array();
-        switch ($t) {
-            case 'c':
-                require_once 'I18Nv2/Country.php';
-                
-                $c = new I18Nv2_Country('en');
-                $ret =  array_keys($c->codes);
-                $ret[] = '**';
-                break;
-            case 'l':
-                require_once 'I18Nv2/Language.php';
-                $c = new I18Nv2_Language('en');
-                $ret =  array_keys($c->codes);
-                $ret[] = '**';
-                break;
-            case 'm':
-                require_once 'I18Nv2/Currency.php';
-                $c = new I18Nv2_Currency('en');
-                $ret =  array_keys($c->codes);
-                $ret[] = '**';
-                break;
-        }
-        foreach ($ret as $k=>$v) {
-            $ret[$k] = strtoupper($v);
-        }
-        
-        
-        return $ret;
-    }
+     
     
      
     function get($s ='')
     {
         
+        $i = DB_DataObject::Factory('I18n');
+        $i->buildDb();
+        $this->outputJavascript();
+    
         
-        switch ($s)
-        {
-            
-            case 'BuildDB':
-            // by admin only?!?
-                //DB_DataObject::debugLevel(1);
-                $this->buildDb('l');
-                $this->buildDb('c');
-                $this->buildDb('m');
-                die("DONE!");
-                break;
-                  
-            default: 
-                $this->outputJavascript();
-                // output javascript..
-                $this->jerr("ERROR");
-        }
-         
-        $this->jdata($ret);
         exit;
         
     }
@@ -174,23 +132,22 @@ class Pman_Core_i18N extends Pman
     function outputJavascript()
     {
         
-        require_once 'I18Nv2/Country.php';
-        require_once 'I18Nv2/Language.php';
-        require_once 'I18Nv2/Currency.php';
+        $i = DB_DataObject::Factory('I18n');
         
-        $langs = $this->cfg['l'];
-        var_dump($langs);exit;
+        $langs = $this->cfg['t'];
+       // var_dump($langs);exit;
         $ar = array();
         foreach($langs as $lang)
         {
-            $lang = array_shift(explode('_', strtoupper($lang)));
+            $rlang = array_shift(explode('_', strtoupper($lang)));
             
             $ar[$lang] = array(
-                'l' => $this->objToList(new I18Nv2_Language($lang, 'UTF-8')),
-                'c' => $this->objToList(new I18Nv2_Country($lang, 'UTF-8')),
-                'm' => $this->objToList(new I18Nv2_Currency($lang, 'UTF-8'))
+                'l' => $i->toTransList('l',  $rlang),
+                'c' => $i->toTransList('c', $rlang),
+                'm' => $i->toTransList('m', $rlang),
             );
         }
+        //echo '<PRE>';print_r($ar);
         header('Content-type: text/javascript');
         echo 'Pman.I18n.Data = ' .  json_encode($ar);
         exit;
@@ -198,12 +155,34 @@ class Pman_Core_i18N extends Pman
         
         
     }
-    function objToList($obj) {
+    
+    function transToList($type, $tolang)
+    {
+        
+        
+        
+    }
+    
+    function objToList($type, $obj) {
         $ret = array();
-        foreach($obj->codes as $k=>$v) {
+         
+         
+        foreach($this->cfg[$type] as $k) {
+            $sub = false;
+            
+            if (strpos($k, '_') !== false) {
+                $bits = explode('_', $k);
+                $k = array_shift($bits);
+                $sub = array_shift($bits);
+            }
+            $v = $k == '**' ? 'Other' : $obj->getName($k);
+            
+            if ($sub) {
+                $v .= ' ('.$sub.')';
+            }
             
             $ret[] = array(
-                'code'=> $k 
+                'code'=>   ($type=='l' ? strtolower($k) : strtoupper($k)) . ($sub ? '_'.strtoupper($sub) : '')
                 'title' => $v
             );
         }
@@ -264,48 +243,6 @@ class Pman_Core_i18N extends Pman
         
         
     }
-    
-    
-    
-    function buildDB($ltype= false, $inlang= false )
-    {
-        if ($ltype === false) {
-            
-            die("OOPS NO LTYPE");
-        }
-        if ($inlang == '**') {
-            return; // dont bother building generic..
-        }
-        if ($inlang === false) {
-            foreach( $this->cfg['t'] as $l) {
-                $this->buildDB($ltype, $l);
-            }
-            return;
-        }
-        
-        $list =  $this->getDefaultCfg($ltype);
-        
-        DB_DataObject::debugLevel(1);
-        
-        foreach($list as $lkey) {
-            $x = DB_DataObject::factory('i18n');
-            $x->ltype = $ltype;
-            $x->lkey = $lkey;
-            $x->inlang= $inlang;
-            if ($x->find(true)) {
-                $xx= clone($x);
-                $x->lval = $this->translate($inlang, $ltype, $lkey);
-                $x->update($xx);
-                continue;
-            }
-            $x->lval = $this->translate($inlang, $ltype, $lkey);
-            $x->insert();
-            
-        }
-        
-        
-        
-        
-    }
+     
     
 }
\ No newline at end of file