I18n.php
[Pman.Core] / I18n.php
index 6e54e76..224d6b6 100644 (file)
--- a/I18n.php
+++ b/I18n.php
@@ -9,7 +9,11 @@
  * By default it returns
  * 
  * Pman.I18n.Data = {
-      en : [ { code : 'end', title : 'English' }, .... ],
+      
+      en : {
+          l :  [ { code : 'en', title : 'English' }, .... ],
+          c :  [ { code : 'UK', title : 'United Kingdom' }, .... ],
+          m :  [ { code : 'USD', title : 'US Dollars' }, .... ],
       fr : ....
    }
  * 
@@ -48,8 +52,17 @@ 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
@@ -80,16 +93,16 @@ 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;
+        
         
         // load the cofiguration
         foreach($opts as $k=>$v) {
             
-            if ($v == '*') {
+            if ($v == '*') { // everything..
                 $this->cfg[$k] = $this->getDefaultCfg($k);
                 continue;
             }
@@ -125,6 +138,7 @@ class Pman_Core_i18N extends Pman
                 $ret[] = '**';
                 break;
         }
+        
         foreach ($ret as $k=>$v) {
             $ret[$k] = strtoupper($v);
         }
@@ -161,7 +175,59 @@ class Pman_Core_i18N extends Pman
         
     }
     
-    
+    function outputJavascript()
+    {
+        
+        require_once 'I18Nv2/Country.php';
+        require_once 'I18Nv2/Language.php';
+        require_once 'I18Nv2/Currency.php';
+        
+        $langs = $this->cfg['t'];
+       // var_dump($langs);exit;
+        $ar = array();
+        foreach($langs as $lang)
+        {
+            $rlang = array_shift(explode('_', strtoupper($lang)));
+            
+            $ar[$lang] = array(
+                'l' => $this->objToList('l', new I18Nv2_Language($rlang, 'UTF-8')),
+                'c' => $this->objToList('c', new I18Nv2_Country($rlang, 'UTF-8')),
+                'm' => $this->objToList('m', new I18Nv2_Currency($rlang, 'UTF-8'))
+            );
+        }
+        //echo '<PRE>';print_r($ar);
+        header('Content-type: text/javascript');
+        echo 'Pman.I18n.Data = ' .  json_encode($ar);
+        exit;
+        
+        
+        
+    }
+    function objToList($type, $obj) {
+        $ret = array();
+         
+         
+        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'=>   ($type=='l' ? strtolower($k) : strtoupper($k)) . ($sub ? '_'.strtoupper($sub) : ''), 
+                'title' => $v
+            );
+        }
+        return $ret;
+    }
     
      /**
      * translate (used by database building);
@@ -230,7 +296,7 @@ class Pman_Core_i18N extends Pman
             return; // dont bother building generic..
         }
         if ($inlang === false) {
-            foreach( $this->cfg['l'] as $l) {
+            foreach( $this->cfg['t'] as $l) {
                 $this->buildDB($ltype, $l);
             }
             return;