From 5c7a17b460b141246dfaea7a702a598c879890fd Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Tue, 15 Dec 2020 14:44:23 +0800 Subject: [PATCH] Fix #6494 - translations code for reports --- Import/Core_templatestr.php | 193 ++++++++++++++ Pman.Tab.AdminTranslationInt.bjs | 248 +++++++++++++++++ Pman.Tab.AdminTranslationInt.js | 438 +++++++++++++++++++++++++++++++ Pman.Tab.AdminTranslations.bjs | 33 ++- Pman.Tab.AdminTranslations.js | 52 +++- UpdateBjsTemplates.php | 54 +++- 6 files changed, 996 insertions(+), 22 deletions(-) create mode 100644 Import/Core_templatestr.php create mode 100644 Pman.Tab.AdminTranslationInt.bjs create mode 100644 Pman.Tab.AdminTranslationInt.js diff --git a/Import/Core_templatestr.php b/Import/Core_templatestr.php new file mode 100644 index 0000000..9f9e773 --- /dev/null +++ b/Import/Core_templatestr.php @@ -0,0 +1,193 @@ +cli; + if ($cli) { + $this->cli = true; + return true; + } + parent::getAuth(); + $au = $this->getAuthUser(); + if (!$au) { + $this->jerrAuth(); + } + return true; + } + + function post($base = '' ) + { + + // should handle uploaded file.. + if (empty($_FILES['imageUpload']['tmp_name']) || + empty($_FILES['imageUpload']['name']) || + empty($_FILES['imageUpload']['type']) + ) { + $this->jerr ("Missing file details"); + exit; + } + + PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError')); + + + $this->transObj = DB_DataObject::factory('core_enum'); + + $this->transObj->query('BEGIN'); + + // first convert the file to a readable format.. + //$rows = $this->readXLS("/home/alan/Downloads/oll_example.xls") ; + $rows = $this->readXLS($_FILES['imageUpload']['tmp_name']) ; + + //$ret = $this->processRows($rows); + + + $this->jok("DONE", false, array('extra'=> $rows)); + + } + + /* + function get($base = '', $opts = array()) + { + $rows = $this->readXLS("/var/lib/php/sessions/pressrelease-translations.xls") ; + + + + $ret = $this->processRows($rows); + + $this->jdata($ret); + exit; + + } + */ + function processRows($rows) + { + $ret = array(); + foreach($rows as $r) { + $ret[] = $this->updateTranslation($r); + + } + return $ret; + } + + + var $seq = 1; + function updateTranslation($r) + { + //print_R($r); DB_DataObject::DebugLevel(1); + $tr = DB_DataObject::Factory('core_templatestr'); + $tr->autoJoin(); + + + $tr->whereAdd("join_template_id_id.template='{$tr->escape($r['template'])}'"); + $tr->whereAdd("join_template_id_id.view_name='{$tr->escape($r['module'])}'"); + $tr->whereAdd("join_src_id_id.mdsum='{$tr->escape($r['code'])}'"); + $tr->lang = $r['language']; + if ($tr->find(true)) { + $tt = DB_DataObject::Factory('core_templatestr'); + $tt->get($tr->id); + $tr= clone($tt); + $tt->txt = $r['translation']; + $tt->updated = date('Y-m-d H:i:s'); + $tt->update($tr); + + return 1; + } + return 0; + } + + + function readXLS($file) { + + require_once 'System.php'; + $ssconvert = System::which('ssconvert'); + if (!$ssconvert) die("ssconvert not installed"); + $csv = $this->tempName('csv'); + $cmd = "$ssconvert -T Gnumeric_stf:stf_csv ". escapeshellarg($file) . ' '.$csv; + + $data= `$cmd`; + + clearstatcache(); + if (!file_exists($csv)) { + $this->jerr("Failed to make file . \n". + $cmd . "\n" . + $data + ); + + + } + //echo $data; + $fh = fopen($csv, 'r'); + if (!$fh) { + $this->jerr("file invalid"); + } + $rows = array(); + $head = false; + $blank = 0; + while (false !== ($row = fgetcsv($fh))) { + + if ($head === false) { + + $h = $row; + // skip header lines. + array_shift($h); + if (!strlen(implode('', $h))) { + continue; + } + // how many empty rows.. + if (count(explode(',',(rtrim(implode(',', $h), " ,")))) < 3) { + continue; + } + + $head = array(); + foreach($row as $i=>$c) { + $c = preg_replace('/[\t \n]+/', ' ', $c); + $head[$i] = strtolower(trim($c)); + } + continue; + } + + if (!strlen(trim(implode('', $h)))) { + $blank++; + if ($blank > 3) { + break; + } + continue; + } + + $blank = 0; + $rrow = array(); + foreach($row as $i=>$c) { + $c = preg_replace('/[\t \n]+/', ' ', $c); + $rrow[$head[$i]] = trim($c); + } + // var_dump($row); + // print_r($max); + $rows[] = $rrow; + } + unlink($csv); + return $rows; + + + } + +} \ No newline at end of file diff --git a/Pman.Tab.AdminTranslationInt.bjs b/Pman.Tab.AdminTranslationInt.bjs new file mode 100644 index 0000000..418594a --- /dev/null +++ b/Pman.Tab.AdminTranslationInt.bjs @@ -0,0 +1,248 @@ +{ + "name" : "Pman.Tab.AdminTranslationsInt", + "parent" : "Pman.Tab.Admin", + "title" : "Admin - AdminTranslationsInt", + "path" : "/home/alan/gitlive/Pman.Admin/Pman.Tab.AdminTranslationInt.bjs", + "permname" : "Admin.TranslationsInt", + "modOrder" : "950", + "strings" : { + "deccbe4e9083c3b5f7cd2632722765bb" : "Translate", + "4994a8ffeba4ac3140beb89e8d41f174" : "Language", + "ae739a236065a45c64ad51aacb19498c" : "Active?", + "d41d8cd98f00b204e9800998ecf8427e" : "", + "6dd08874f83507e9c7b23f1a46b7fa7c" : "Translation", + "83dad8107f9459efe2b4fabcf5b63108" : "Select Language", + "78463a384a5aa4fad5fa73e2f506ecfc" : "English", + "552bcc4e00cd663f09cc4efbaca1cd45" : "Select Translation of", + "ca0dbad92a874b2f69b549293387925e" : "Code", + "0a9e8bd9e8b301dfb2c21c355e0b377d" : "Languages and Countries" + }, + "named_strings" : { + "language_title_value" : "d41d8cd98f00b204e9800998ecf8427e", + "language_title_qtip" : "83dad8107f9459efe2b4fabcf5b63108", + "language_title_fieldLabel" : "4994a8ffeba4ac3140beb89e8d41f174" + }, + "items" : [ + { + "region" : "center", + "title" : "Translate", + "xtype" : "NestedLayoutPanel", + "$ xns" : "Roo", + "items" : [ + { + "xtype" : "BorderLayout", + "$ xns" : "Roo", + "* prop" : "layout", + "items" : [ + { + "alwaysShowTabs" : true, + "xtype" : "LayoutRegion", + "tabPosition" : "top", + "$ xns" : "Roo", + "* prop" : "center" + }, + { + "listeners" : { + "|activate" : "function() {\n _this.langpanel = this;\n if (_this.langgrid) {\n _this.langgrid.ds.load({});\n }\n}" + }, + "region" : "center", + "fitToframe" : true, + "background" : true, + "title" : "Languages and Countries", + "xtype" : "GridPanel", + "fitContainer" : true, + "$ xns" : "Roo", + "tableName" : "i18n", + "items" : [ + { + "listeners" : { + "beforeedit" : "function(e) {\n console.log('beforeedit');\n //if (e.record.get('origtxt').indexOf('<') > -1) {\n // console.log(\"HTML EDITOR!!\");\n \n // return false;\n //}\n if (e.record.get('lval').replace(/\\s+/, '').length) {\n return true;\n }\n \n \n var tl = _this.langgridCombo.getValue();\n \n tl = (tl == 'zh_HK') ? 'zh-TW' : tl; \n tl = tl.replace('_', '-');\n var rec = e.record;\n \n \n \n Pman.gtranslate(e.record.get('lval_en'), 'en', tl, function(result) { \n if (typeof(result) == 'object') { //error\n return; \n }\n \n if (_this.grid.activeEditor) {\n _this.grid.activeEditor.setValue(result);\n } else {\n rec.set('lval',result);\n //_this.saveRec(rec);\n }\n\n //\n \n \n //console.log(result.translation);\n });\n \n \n \n return true;\n } ", + "cellclick" : "function (_self, rowIndex, columnIndex, e)\n{\n if(_this.langgrid.colModel.getDataIndex(columnIndex) !== 'is_active'){\n return;\n }\n \n var s = _this.langgrid.ds.getAt(rowIndex);\n \n if(!s || s.data.id * 1 < 0){\n return;\n }\n \n s.set('is_active', s.data.is_active ? 0 : 1);\n \n new Pman.Request({\n url : baseURL+'/Roo/I18n',\n method : 'POST',\n params : {\n id : s.data.id,\n is_active : s.data.is_active\n }\n }); \n \n}", + "|render" : "function() \n{\n _this.langgrid = this; \n //_this.dialog = Pman.Dialog.FILL_IN\n if (_this.langpanel.active) {\n this.ds.load({});\n }\n}", + "afteredit" : "function (e)\n{\n var saveRec = function(rec)\n {\n var g = _this.grid;\n\n //g.getView().el.mask('Saving');\n Ext.Ajax.request({\n url : baseURL + '/Roo/I18n.php',\n method: 'POST',\n params : {\n id : rec.get('id'),\n lval : rec.get('lval'),\n ltype : rec.get('ltype')\n },\n success : function()\n {\n //g.getView().el.unmask();\n //g.getDataSource().reload();\n },\n failure : function()\n {\n Ext.Msg.alert(\"Error\", \"There was a problem saving the data - try reloading\");\n // g.getView().el.unmask();\n }\n \n });\n };\n \n saveRec.defer(1000, _this, [ e.record ]);\n}" + }, + "autoExpandColumn" : "lval", + "xtype" : "EditorGrid", + "loadMask" : true, + "clicksToEdit" : 1, + "$ xns" : "Roo.grid", + "* prop" : "grid", + "items" : [ + { + "listeners" : { + "beforeload" : "function (_self, options)\n{\n options =options || {};\n options.params =options.params|| {};\n options.params.ltype = _this.langtypeCombo.getValue();\n options.params.inlang = _this.langgridCombo.getValue();\n options.params['query[_with_en]'] = 1;\n if (!options.params.ltype.length || !options.params.inlang.length) {\n return false;\n }\n \n options.params.limit = 9999;\n \n}" + }, + "xtype" : "Store", + "remoteSort" : true, + "$ sortInfo" : "{ field : 'lkey', direction: 'ASC' }", + "$ xns" : "Roo.data", + "* prop" : "dataSource", + "items" : [ + { + "$ url" : "baseURL + '/Roo/i18n.php'", + "xtype" : "HttpProxy", + "method" : "GET", + "$ xns" : "Roo.data", + "* prop" : "proxy" + }, + { + "id" : "id", + "root" : "data", + "xtype" : "JsonReader", + "$ xns" : "Roo.data", + "$ fields" : "[\n {\n 'name': 'id',\n 'type': 'int'\n },\n {\n 'name': 'ltype',\n 'type': 'string'\n },\n {\n 'name': 'lkey',\n 'type': 'string'\n },\n {\n 'name': 'inlang',\n 'type': 'string'\n },\n {\n 'name': 'lval',\n 'type': 'string'\n }\n]", + "* prop" : "reader", + "totalProperty" : "total" + } + ] + }, + { + "xtype" : "Toolbar", + "$ xns" : "Roo", + "* prop" : "toolbar", + "items" : [ + { + "listeners" : { + "|render" : "function (_self)\n{\n _this.langtypeCombo = _self;\n}", + "|select" : "function (combo, record, index)\n{\n _this.langgrid.getDataSource().reload(); \n}" + }, + "triggerAction" : "all", + "selectOnFocus" : true, + "emptyText" : "Select Translation of", + "displayField" : "lval", + "valueField" : "lkey", + "xtype" : "ComboBox", + "typeAhead" : false, + "editable" : false, + "width" : 200, + "$ xns" : "Roo.form", + "mode" : "local", + "items" : [ + { + "xtype" : "SimpleStore", + "$ data" : "[\n [ 'l', 'Language Names' ],\n [ 'c', 'Country Names' ],\n [ 'm', 'Currency Names' ]\n]", + "$ fields" : "['lkey','lval']", + "$ xns" : "Roo.data", + "* prop" : "store" + } + ] + }, + { + "listeners" : { + "render" : "function (_self)\n{\n _this.langgridCombo=_self;\n}", + "select" : "function (combo, record, index)\n{\n _this.langgrid.getDataSource().reload(); \n}" + }, + "listWidth" : 300, + "Number pageSize" : 400, + "triggerAction" : "all", + "Number minChars" : 2, + "fieldLabel" : "Language", + "selectOnFocus" : true, + "String queryParam" : "query[name_starts]", + "displayField" : "title", + "hiddenName" : "language", + "value" : "", + "valueField" : "code", + "xtype" : "ComboBox", + "allowBlank" : false, + "typeAhead" : true, + "editable" : true, + "width" : 200, + "$ xns" : "Roo.form", + "name" : "language_title", + "qtip" : "Select Language", + "items" : [ + { + "listeners" : { + "beforeload" : "function (_self, options)\n{\n options =options || {};\n options.params =options.params|| {};\n options.params.ltype = 'l';\n options.params.inlang = 'en';\n \n options.params._as_code_and_title = 1;\n \n}" + }, + "$ Object sortInfo" : "{ field : 'title', direction: 'ASC' }", + "xtype" : "Store", + "$ xns" : "Roo.data", + "* prop" : "store", + "items" : [ + { + "$ url" : "baseURL + '/Roo/i18n.php'", + "method" : "GET", + "xtype" : "HttpProxy", + "$ xns" : "Roo.data", + "* prop" : "proxy" + }, + { + "id" : "id", + "root" : "data", + "xtype" : "JsonReader", + "$ xns" : "Roo.data", + "$ fields" : "[\n {\n 'name': 'id',\n 'type': 'int'\n },\n {\n 'name': 'ltype',\n 'type': 'string'\n },\n {\n 'name': 'lkey',\n 'type': 'string'\n },\n {\n 'name': 'inlang',\n 'type': 'string'\n },\n {\n 'name': 'lval',\n 'type': 'string'\n } \n]", + "* prop" : "reader", + "totalProperty" : "total" + } + ] + } + ] + } + ] + }, + { + "xtype" : "ColumnModel", + "width" : 50, + "header" : "Code", + "$ renderer" : "function(v) { return String.format('{0}', v); }", + "$ xns" : "Roo.grid", + "Boolean sortable" : true, + "* prop" : "colModel[]", + "dataIndex" : "lkey" + }, + { + "xtype" : "ColumnModel", + "width" : 150, + "header" : "English", + "$ renderer" : "function(v) { return String.format('{0}', v); }", + "$ xns" : "Roo.grid", + "Boolean sortable" : true, + "* prop" : "colModel[]", + "dataIndex" : "lval_en" + }, + { + "xtype" : "ColumnModel", + "width" : 200, + "header" : "Translation", + "$ renderer" : "function(v) { return String.format('{0}', v); }", + "$ xns" : "Roo.grid", + "Boolean sortable" : true, + "* prop" : "colModel[]", + "dataIndex" : "lval", + "items" : [ + { + "xtype" : "GridEditor", + "$ xns" : "Roo.grid", + "* prop" : "editor", + "items" : [ + { + "xtype" : "TextField", + "$ xns" : "Roo.form", + "* prop" : "field" + } + ] + } + ] + }, + { + "xtype" : "ColumnModel", + "width" : 150, + "header" : "Active?", + "$ renderer" : "function(v,x,r) { \n\n return '';\n \n \n}", + "$ xns" : "Roo.grid", + "* prop" : "colModel[]", + "dataIndex" : "is_active" + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/Pman.Tab.AdminTranslationInt.js b/Pman.Tab.AdminTranslationInt.js new file mode 100644 index 0000000..3425776 --- /dev/null +++ b/Pman.Tab.AdminTranslationInt.js @@ -0,0 +1,438 @@ +//