typo
[Pman.Admin] / Translations.php
index 4790388..a0c8aec 100644 (file)
@@ -1,5 +1,8 @@
 <?php
 
+die("NOT USED!?");
+// see core_template code..
+
 
 /**
  * Pman_Admin_Translation:
@@ -41,8 +44,35 @@ class Pman_Admin_Translations extends Pman
     }
     
     
-    function get()
+    function get($module, $opts = Array())
     {
+        
+        if (!empty($module)) {
+            $this->init();
+            //DB_DataObject::debugLevel(1);
+            require_once 'Services/JSON.php';
+            $d = DB_DataObject::factory('translations');
+            $d->module = $module;
+            $d->selectAdd();
+            $d->selectAdd('distinct(tlang) as tlang');
+            header('Content-type: text/javascript');
+            $langs= $d->fetchAll('tlang');
+            foreach($langs as $lang) {
+                // output the translations strings file..
+                
+                    
+                $this->loadOriginalStrings($module);
+                
+                $data = $this->loadTranslateDB($lang,$module);
+                
+                $j = new Services_JSON();
+                echo "_T.{$lang}= Roo.apply( _T.{$lang} || { }, " .  $j->stringify($data, null, 4) . ");\n";
+                
+            }
+            exit;
+            
+        }
+        
         // load and parse json file containing all translations...
         if (isset($_REQUEST['id'])) {
             return $this->post();
@@ -62,10 +92,12 @@ class Pman_Admin_Translations extends Pman
         $module = $_REQUEST['module'];
         
         
-         $this->loadOriginalStrings($module); // what needs translating..
-        
-        
+        $this->loadOriginalStrings($module); // what needs translating..
         
+        $ff = $this->bootLoader;
+        if (empty($ff->Pman['public_cache_dir'])) {
+            $this->jerr("public_cache_dir has not been set up");
+        }
         
         
         
@@ -79,7 +111,7 @@ class Pman_Admin_Translations extends Pman
         foreach($this->original as $k=>$ar) {
             foreach($ar as $tr=>$trv) {
                 // $hint = isset($hints[$tr]) ? $hints[$tr] : '';
-                $key = md5($k.'-'.$tr);
+                $key = $trv;
                 $ret[] = array(
                     'id' => $lang.'/'.$key,
                     'msum' => $key,
@@ -100,7 +132,7 @@ class Pman_Admin_Translations extends Pman
         
     }
     
-    function post() 
+    function post($v
     {
          
          
@@ -145,16 +177,47 @@ class Pman_Admin_Translations extends Pman
         // since this can handle errors better.!!?
         $info = $this->moduleJavascriptFilesInfo($module);
         //print_r($info);
-        $tfile =$info->basedir . '/'. $info->translation_data;
+        
+        
+        
+        $this->original  = array();
+        $tfile = $info->basedir . '/'. $info->translation_data;
          //var_dump($tfile);
-        if (empty($tfile) || !file_exists($tfile)) {
-            return array();
-        }
+        //if (empty($tfile) || !file_exists($tfile)) {
+            
+            foreach($info->filesmtime as $f =>$mt) {
+                $bjs = preg_replace('/\.js$/','.bjs', $f);
+                if (!file_exists($bjs)) {
+                    continue;
+                }
+                $jd = json_decode(file_get_contents($bjs));
+                if (empty($jd->strings)) {
+                    continue;
+                }
+                foreach($jd->strings as $tkey => $val) {
+                    $line = array(
+                        'module' => $module,
+                        'tfile' => preg_replace('/\.js$/','',  basename($bjs)),
+                    );
+                    
+                    
+                }
+                
+                $this->original[str_replace('.bjs', '', basename($bjs)) ] = array_flip((array)$jd->strings);
+            }
+             
+            file_put_contents($tfile, json_encode($this->original));
+            
+            
+        //}
         
         
-        require_once 'Services/JSON.php';
-        $j = new Services_JSON();
-        $this->original = $j->decode('{'. file_get_contents($tfile).'}');
+        print_R($this->original);exit;
+        
+        
+        $this->original = (array) json_decode( file_get_contents($tfile) );
+        ksort($this->original);
+
         $this->originalKeys = array();
         
         // 
@@ -187,8 +250,9 @@ class Pman_Admin_Translations extends Pman
         //DB_DataObject::debugLevel(1);
         $d = DB_DataObject::factory('translations');
         $d->module = $module;
-        $d->lang = $lang;
-        
+        $d->tlang = $lang;
+        $d->whereAdd('LENGTH(tval) > 0');
+        $ret = array();
         
         if ($d->count()) {
             // since key includes file 
@@ -218,13 +282,13 @@ class Pman_Admin_Translations extends Pman
             if (!isset($this->originalKeys[$k])) {
                 continue;
             }
+            
             // it's current..
             $this->saveTranslateDB($lang, $module, $this->originalKeys[$k], $k, $v);
             $ret[$k] = $v;
             
             
         }
-        
         return $ret;
         
          
@@ -234,7 +298,7 @@ class Pman_Admin_Translations extends Pman
     {
         $d = DB_DataObject::factory('translations');
         $d->module = $module;
-        $d->lang = $lang;
+        $d->tlang = $lang;
         $d->tfile = $tfile;
         $d->tkey = $tkey;
         if ($d->find(true)) {
@@ -308,6 +372,6 @@ class Pman_Admin_Translations extends Pman
         //$this->writeTrans($lang);
     }
      
-    
+     
     
 }
\ No newline at end of file