Fix #6503 - translations not working yet
authorAlan Knowles <alan@roojs.com>
Tue, 15 Dec 2020 07:11:52 +0000 (15:11 +0800)
committerAlan Knowles <alan@roojs.com>
Tue, 15 Dec 2020 07:11:52 +0000 (15:11 +0800)
InterfaceTranslations.php
Translations.php

index e3de56f..922b468 100644 (file)
  * 
  */
 
-require_once 'Pman/Admin/Translations.php';
+require_once 'Pman.php';
 
-class Pman_Admin_InterfaceTranslations extends Pman_Admin_Translations 
+class Pman_Admin_InterfaceTranslations extends Pman 
 {
+     var $prefix = '';
+    var $fn = '';
+    var $data = array();
+    
+    var $original = array() ; // filename => array( orig_string > orig_string)
+    var $originalKeys = array() ; // md5(filename-orig_string) => filename
      
     function getAuth()
     {
@@ -65,4 +71,119 @@ class Pman_Admin_InterfaceTranslations extends Pman_Admin_Translations
         $this->jerr("invalid url"); 
      
     }
+    
+     /**
+     * load strings that need translating..
+     */
+    
+    function loadOriginalStrings($module)
+    {
+        // since this can handle errors better.!!?
+        $info = $this->moduleJavascriptFilesInfo($module);
+        //print_r($info);
+        
+        
+        
+        $this->original  = array();
+        $tfile = $info->basedir . '/'. $info->translation_data;
+         //var_dump($tfile);
+        //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;
+                }
+                $this->original[str_replace('.bjs', '', basename($bjs)) ] = array_flip((array)$jd->strings);
+            }
+             
+            file_put_contents($tfile, json_encode($this->original));
+            
+            
+        //}
+        
+        
+        print_R($this->original);exit;
+        
+        
+        $this->original = (array) json_decode( file_get_contents($tfile) );
+        ksort($this->original);
+
+        $this->originalKeys = array();
+        
+        // 
+        foreach($this->original as $k=>$ar) {
+            foreach($ar as $tr=>$trv) {
+                $key = md5($k.'-'.$tr);
+                $this->originalKeys[$key] = $k;
+            }
+        }
+        
+    }
+    
+    /***
+     *
+     * loadTranslateDB -
+     *
+     *
+     * @return key=>value list of translation_id=>tranlation.
+     *
+     *
+     */
+    
+    function loadTranslateDB($lang, $module)
+    {
+        
+        //DB_DataObject::debugLevel(1);
+        $d = DB_DataObject::factory('translations');
+        $d->module = $module;
+        $d->tlang = $lang;
+        $d->whereAdd('LENGTH(tval) > 0');
+        $ret = array();
+        
+        if ($d->count()) {
+            // since key includes file 
+            $ret = $d->fetchAll('tkey','tval'); /// shoudl we include updates
+        }
+        // no data is contained in the database, we should initialize it, if we can
+        $info  = $this->moduleJavascriptFilesInfo($module);
+        $fn = $info->module_dir.'/_translations_/'.$lang.'.js';
+        
+       
+        if (!file_exists($fn)) {
+            ///Die($fn ." does not exist?");
+            return $ret;
+        }
+        
+        
+        $default = (array) json_decode(file_get_contents($fn));
+        //echo '<PRE>';print_r($default); print_r($this->originalKeys);exit;
+        
+        
+        
+        foreach($default as $k=>$v) {
+            if (isset($ret[$k])) {
+                continue; // skip database already holds a version of this translation.
+            }
+            // is it relivant anymore..
+            if (!isset($this->originalKeys[$k])) {
+                continue;
+            }
+            
+            // it's current..
+            $this->saveTranslateDB($lang, $module, $this->originalKeys[$k], $k, $v);
+            $ret[$k] = $v;
+            
+            
+        }
+        return $ret;
+        
+         
+    }
+    
+    
 }
\ No newline at end of file
index b0f3690..e4d1410 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 
-// see core_template code..
+
 /**
  * Pman_Admin_Translation:
  * - the latest version of this....