From e4f2b17d7cb99359d96aa218d40f66598ed9e711 Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Tue, 15 Dec 2020 15:11:52 +0800 Subject: [PATCH] Fix #6503 - translations not working yet --- InterfaceTranslations.php | 125 +++++++++++++++++++++++++++++++++++++- Translations.php | 3 +- 2 files changed, 124 insertions(+), 4 deletions(-) diff --git a/InterfaceTranslations.php b/InterfaceTranslations.php index e3de56f..922b468 100644 --- a/InterfaceTranslations.php +++ b/InterfaceTranslations.php @@ -17,10 +17,16 @@ * */ -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 '
';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
diff --git a/Translations.php b/Translations.php
index b0f3690..e4d1410 100644
--- a/Translations.php
+++ b/Translations.php
@@ -1,7 +1,6 @@