From 850b5867e1e453f98e7994fbf1bfededd106970c Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Sat, 20 Jan 2018 14:23:36 +0200 Subject: [PATCH] Few bug fixes to the translation manager --- README.md | 4 +- admin/README.txt | 4 +- admin/models/import_language_translations.php | 64 +++++++++++++------ admin/models/joomla_component.php | 26 +++++--- admin/models/language_translation.php | 6 +- admin/models/language_translations.php | 52 ++++++++++----- componentbuilder.xml | 2 +- 7 files changed, 105 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index ced6e2e9f..970871d20 100644 --- a/README.md +++ b/README.md @@ -126,11 +126,11 @@ Component Builder is mapped as a component in itself on my local development env + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](http://joomlacomponentbuilder.com) + *First Build*: 30th April, 2015 -+ *Last Build*: 19th January, 2018 ++ *Last Build*: 20th January, 2018 + *Version*: 2.6.12 + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html -+ *Line count*: **180465** ++ *Line count*: **180517** + *Field count*: **1573** + *File count*: **1160** + *Folder count*: **186** diff --git a/admin/README.txt b/admin/README.txt index ced6e2e9f..970871d20 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -126,11 +126,11 @@ Component Builder is mapped as a component in itself on my local development env + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](http://joomlacomponentbuilder.com) + *First Build*: 30th April, 2015 -+ *Last Build*: 19th January, 2018 ++ *Last Build*: 20th January, 2018 + *Version*: 2.6.12 + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html -+ *Line count*: **180465** ++ *Line count*: **180517** + *Field count*: **1573** + *File count*: **1160** + *Folder count*: **186** diff --git a/admin/models/import_language_translations.php b/admin/models/import_language_translations.php index 56ea20c3d..1b01ae202 100644 --- a/admin/models/import_language_translations.php +++ b/admin/models/import_language_translations.php @@ -501,9 +501,10 @@ class ComponentbuilderModelImport_language_translations extends JModelLegacy // raw items import & update! $query = $db->getQuery(true); $query - ->select('version') + ->select($db->quoteName(array('version', 'translation'))) ->from($db->quoteName('#__componentbuilder_'.$table)) - ->where($db->quoteName('id') . ' = '. $db->quote($row[$id_key])); + ->where($db->quoteName('id') . ' = '. $db->quote($row[$id_key])) + ->where($db->quoteName('entranslation') . ' = '. $db->quote($row[$english_key])); // Reset the query using our newly populated query object. $db->setQuery($query); $db->execute(); @@ -514,14 +515,25 @@ class ComponentbuilderModelImport_language_translations extends JModelLegacy { // update item $id = $row[$id_key]; - $version = $db->loadResult(); + $item = $db->loadObject(); + // load previous translation strings + if (ComponentbuilderHelper::checkJson($item->translation)) + { + $translations = json_decode($item->translation, true); + $counter = count($translations) + 2; + $pre = true; + } + else + { + $translations = array(); + $counter = 0; + $pre = false; + } // get languages $languages = ComponentbuilderHelper::getVars('language', 1, 'published', 'langtag'); // reset all buckets $query = $db->getQuery(true); $fields = array(); - $translations = array(); - $counter = 0; // Fields to update. foreach($row as $key => $cell) { @@ -533,7 +545,7 @@ class ComponentbuilderModelImport_language_translations extends JModelLegacy // update version if ('version' == $target[$key]) { - $cell = (int) $version + 1; + $cell = (int) $item->version + 1; } // verify publish authority if ('published' == $target[$key] && !$canState) @@ -546,6 +558,20 @@ class ComponentbuilderModelImport_language_translations extends JModelLegacy // only add if it has a string if (ComponentbuilderHelper::checkString($cell)) { + // remove if was set previously + if ($pre) + { + $tag = $target[$key]; + $translations = array_filter( + $translations, + function($trans) use($tag) { + if ($trans['language'] !== $tag) + { + return true; + } + return false; + }); + } $translations['translation'.$counter] = array('language' => $target[$key], 'translation' => $cell); $counter++; } @@ -569,22 +595,18 @@ class ComponentbuilderModelImport_language_translations extends JModelLegacy if (ComponentbuilderHelper::checkArray($translations)) { $fields[] = $db->quoteName('translation') . ' = ' . $db->quote(json_encode($translations, JSON_FORCE_OBJECT)); - } - // load the defaults - $fields[] = $db->quoteName('modified_by') . ' = ' . $db->quote($user->id); - $fields[] = $db->quoteName('modified') . ' = ' . $db->quote($todayDate); - // Conditions for which records should be updated. - $conditions = array( - $db->quoteName('id') . ' = ' . $id - ); + // load the defaults + $fields[] = $db->quoteName('modified_by') . ' = ' . $db->quote($user->id); + $fields[] = $db->quoteName('modified') . ' = ' . $db->quote($todayDate); + // Conditions for which records should be updated. + $conditions = array( + $db->quoteName('id') . ' = ' . $id + ); - $query->update($db->quoteName('#__componentbuilder_'.$table))->set($fields)->where($conditions); - $db->setQuery($query); - $db->execute(); - } - else - { - return false; + $query->update($db->quoteName('#__componentbuilder_'.$table))->set($fields)->where($conditions); + $db->setQuery($query); + $db->execute(); + } } } return true; diff --git a/admin/models/joomla_component.php b/admin/models/joomla_component.php index 17e664989..5e7ac68c9 100644 --- a/admin/models/joomla_component.php +++ b/admin/models/joomla_component.php @@ -418,6 +418,8 @@ class ComponentbuilderModelJoomla_component extends JModelAdmin // prep the lang strings for export if (isset($_export) && $_export && ComponentbuilderHelper::checkArray($items)) { + // insure we have the same order in the languages + $languages = ComponentbuilderHelper::getVars('language', 1, 'published', 'langtag'); foreach ($items as $nr => &$item) { // remove some values completely @@ -432,18 +434,26 @@ class ComponentbuilderModelJoomla_component extends JModelAdmin unset($item->hits); unset($item->access); unset($item->ordering); - // now adapt the entranslation - if (isset($item->translation) && ComponentbuilderHelper::checkJson($item->translation)) + // set the lang order + if ($nr != 0) { - $translations = json_decode($item->translation, true); - if (ComponentbuilderHelper::checkArray($translations)) + foreach ($languages as $lanTag) { - foreach ($translations as $language) + $item->{$lanTag} = ''; + } + // now adapt the entranslation + if (isset($item->translation) && ComponentbuilderHelper::checkJson($item->translation)) + { + $translations = json_decode($item->translation, true); + if (ComponentbuilderHelper::checkArray($translations)) { - if (isset($language['translation']) && ComponentbuilderHelper::checkString($language['translation']) - && isset($language['language']) && ComponentbuilderHelper::checkString($language['language'])) + foreach ($translations as $language) { - $item->{$language['language']} = $language['translation']; + if (isset($language['translation']) && ComponentbuilderHelper::checkString($language['translation']) + && isset($language['language']) && ComponentbuilderHelper::checkString($language['language'])) + { + $item->{$language['language']} = $language['translation']; + } } } } diff --git a/admin/models/language_translation.php b/admin/models/language_translation.php index 77370ad75..40ced8708 100644 --- a/admin/models/language_translation.php +++ b/admin/models/language_translation.php @@ -107,13 +107,13 @@ class ComponentbuilderModelLanguage_translation extends JModelAdmin $translation->loadString($item->translation); $item->translation = $translation->toArray(); } - + if (!empty($item->components)) { // JSON Decode components. - $item->components = json_decode($item->components); + $item->components = json_decode($item->components, true); } - + if (empty($item->id)) { diff --git a/admin/models/language_translations.php b/admin/models/language_translations.php index c682b59e4..45c6fbf18 100644 --- a/admin/models/language_translations.php +++ b/admin/models/language_translations.php @@ -164,6 +164,8 @@ class ComponentbuilderModelLanguage_translations extends JModelList // prep the lang strings for export if (isset($_export) && $_export && ComponentbuilderHelper::checkArray($items)) { + // insure we have the same order in the languages + $languages = ComponentbuilderHelper::getVars('language', 1, 'published', 'langtag'); foreach ($items as $nr => &$item) { // remove some values completely @@ -178,18 +180,26 @@ class ComponentbuilderModelLanguage_translations extends JModelList unset($item->hits); unset($item->access); unset($item->ordering); - // now adapt the entranslation - if (isset($item->translation) && ComponentbuilderHelper::checkJson($item->translation)) + // set the lang order + if ($nr != 0) { - $translations = json_decode($item->translation, true); - if (ComponentbuilderHelper::checkArray($translations)) + foreach ($languages as $lanTag) { - foreach ($translations as $language) + $item->{$lanTag} = ''; + } + // now adapt the entranslation + if (isset($item->translation) && ComponentbuilderHelper::checkJson($item->translation)) + { + $translations = json_decode($item->translation, true); + if (ComponentbuilderHelper::checkArray($translations)) { - if (isset($language['translation']) && ComponentbuilderHelper::checkString($language['translation']) - && isset($language['language']) && ComponentbuilderHelper::checkString($language['language'])) + foreach ($translations as $language) { - $item->{$language['language']} = $language['translation']; + if (isset($language['translation']) && ComponentbuilderHelper::checkString($language['translation']) + && isset($language['language']) && ComponentbuilderHelper::checkString($language['language'])) + { + $item->{$language['language']} = $language['translation']; + } } } } @@ -387,6 +397,8 @@ class ComponentbuilderModelLanguage_translations extends JModelList // prep the lang strings for export if (isset($_export) && $_export && ComponentbuilderHelper::checkArray($items)) { + // insure we have the same order in the languages + $languages = ComponentbuilderHelper::getVars('language', 1, 'published', 'langtag'); foreach ($items as $nr => &$item) { // remove some values completely @@ -401,18 +413,26 @@ class ComponentbuilderModelLanguage_translations extends JModelList unset($item->hits); unset($item->access); unset($item->ordering); - // now adapt the entranslation - if (isset($item->translation) && ComponentbuilderHelper::checkJson($item->translation)) + // set the lang order + if ($nr != 0) { - $translations = json_decode($item->translation, true); - if (ComponentbuilderHelper::checkArray($translations)) + foreach ($languages as $lanTag) { - foreach ($translations as $language) + $item->{$lanTag} = ''; + } + // now adapt the entranslation + if (isset($item->translation) && ComponentbuilderHelper::checkJson($item->translation)) + { + $translations = json_decode($item->translation, true); + if (ComponentbuilderHelper::checkArray($translations)) { - if (isset($language['translation']) && ComponentbuilderHelper::checkString($language['translation']) - && isset($language['language']) && ComponentbuilderHelper::checkString($language['language'])) + foreach ($translations as $language) { - $item->{$language['language']} = $language['translation']; + if (isset($language['translation']) && ComponentbuilderHelper::checkString($language['translation']) + && isset($language['language']) && ComponentbuilderHelper::checkString($language['language'])) + { + $item->{$language['language']} = $language['translation']; + } } } } diff --git a/componentbuilder.xml b/componentbuilder.xml index 3db462a41..349cb6464 100644 --- a/componentbuilder.xml +++ b/componentbuilder.xml @@ -1,7 +1,7 @@ COM_COMPONENTBUILDER - 19th January, 2018 + 20th January, 2018 Llewellyn van der Merwe llewellyn@joomlacomponentbuilder.com http://joomlacomponentbuilder.com