From 4cf145ac415e98d1724e1202d3408b2443e6ea24 Mon Sep 17 00:00:00 2001 From: Bhupesh Pandey <72725957+bhupeshappfoster@users.noreply.github.com> Date: Fri, 26 May 2023 22:15:33 +0530 Subject: [PATCH] Release/3.2.6 * Prevent slug translation feature added * fixed: plugin license status issue * fixed: asset translation issue * Updated: change log and version bumped * Added: global setting for prevent slug translation --- .craftplugin | 2 +- CHANGELOG.md | 9 +++++ src/assetbundles/src/js/OrderDetails.js | 2 + src/controllers/OrderController.php | 15 +++++-- src/controllers/SettingsController.php | 19 +++++---- src/elements/Order.php | 15 +++++++ src/migrations/Install.php | 1 + ...lug_translation_column_to_orders_table.php | 31 +++++++++++++++ src/models/Settings.php | 2 + src/services/ElementToFileConverter.php | 26 +++++++------ src/services/ElementTranslator.php | 15 +++++-- .../fieldtranslator/AssetsFieldTranslator.php | 6 ++- src/services/repository/FileRepository.php | 5 ++- .../_forms/order-entries-table.twig | 2 +- .../_components/_forms/order-files-table.twig | 2 +- src/templates/_components/app-info.twig | 3 +- .../_components/orders/settings-tab.twig | 39 +++++++++++-------- src/templates/_index.twig | 2 +- src/templates/settings/about.twig | 3 -- .../settings/configuration-options.twig | 11 +++++- 20 files changed, 154 insertions(+), 56 deletions(-) create mode 100644 src/migrations/m230503_053114_add_prevent_slug_translation_column_to_orders_table.php diff --git a/.craftplugin b/.craftplugin index 37ed5257..8779bb3e 100644 --- a/.craftplugin +++ b/.craftplugin @@ -1,7 +1,7 @@ { "pluginName": "Translations for Craft", "pluginDescription": "Drive global growth with simplified translation workflows.", - "pluginVersion": "3.2.5", + "pluginVersion": "3.2.6", "pluginAuthorName": "Acclaro", "pluginVendorName": "Acclaro", "pluginAuthorUrl": "http://www.acclaro.com/", diff --git a/CHANGELOG.md b/CHANGELOG.md index ad57d7d7..d275c689 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 3.2.6 - 2023-05-29 + +### Added +- Dedicated `prevent slug translation` button if user does not want slug translation. ([AcclaroInc#436](https://github.com/AcclaroInc/craft-translations/issues/436)) + +### Fixed +- An issue where plugin license was always showing `free trial` despite of `Paid` even after license is purchased. ([AcclaroInc#437](https://github.com/AcclaroInc/craft-translations/issues/437)) +- An issue where asset's title was incuded in source files regardless of translation enabled or not. ([AcclaroInc#439](https://github.com/AcclaroInc/craft-translations/issues/439)) + ## 3.2.5 - 2023-04-15 ### Fixed diff --git a/src/assetbundles/src/js/OrderDetails.js b/src/assetbundles/src/js/OrderDetails.js index 15a44923..226c556d 100644 --- a/src/assetbundles/src/js/OrderDetails.js +++ b/src/assetbundles/src/js/OrderDetails.js @@ -194,6 +194,7 @@ title = $('#title').val(); trackChanges = $('input[type=hidden][name=trackChanges]').val(); trackTargetChanges = $('input[type=hidden][name=trackTargetChanges]').val(); + preventSlugTranslation = $('input[type=hidden][name=preventSlugTranslation]').val(); includeTmFiles = $('input[type=hidden][name=includeTmFiles]').val(); requestQuote = $('input[type=hidden][name=requestQuote]').val(); tags = $('input[name="tags[]"]'); @@ -232,6 +233,7 @@ if (trackChanges) url += "&trackChanges=" + trackChanges if (trackTargetChanges) url += "&trackTargetChanges=" + trackTargetChanges + if (preventSlugTranslation) url += "&preventSlugTranslation=" + preventSlugTranslation if (includeTmFiles) url += "&includeTmFiles=" + includeTmFiles if (requestQuote) url += "&requestQuote=" + requestQuote diff --git a/src/controllers/OrderController.php b/src/controllers/OrderController.php index f37ad5d6..1acc33fb 100644 --- a/src/controllers/OrderController.php +++ b/src/controllers/OrderController.php @@ -193,6 +193,10 @@ public function actionOrderDetail(array $variables = array()) $order->trackTargetChanges = $orderTrackTargetChanges; } + if ($orderPreventSlugTranslation = Craft::$app->getRequest()->getQueryParam('preventSlugTranslation')) { + $order->preventSlugTranslation = $orderPreventSlugTranslation; + } + if ($orderIncludeTmFiles = Craft::$app->getRequest()->getQueryParam('includeTmFiles')) { $order->includeTmFiles = $orderIncludeTmFiles; } @@ -443,6 +447,7 @@ public function actionSaveOrder() $order->trackChanges = Craft::$app->getRequest()->getBodyParam('trackChanges'); $order->trackTargetChanges = Craft::$app->getRequest()->getBodyParam('trackTargetChanges'); $order->includeTmFiles = Craft::$app->getRequest()->getBodyParam('includeTmFiles'); + $order->preventSlugTranslation = Craft::$app->getRequest()->getBodyParam('preventSlugTranslation'); $order->requestQuote = Craft::$app->getRequest()->getBodyParam('requestQuote'); $order->sourceSite = $sourceSite; $order->targetSites = $targetSites ? json_encode($targetSites) : null; @@ -676,6 +681,7 @@ public function actionCloneOrder() $newOrder->title = $data['title'] ?? ''; $newOrder->trackChanges = $variables['shouldTrackSourceContent'] = $data['trackChanges'] ?? null; $newOrder->trackTargetChanges = $variables['shouldTrackTargetContent'] = $data['trackTargetChanges'] ?? null; + $newOrder->preventSlugTranslation = $variables['shouldPreventSlugTranslation'] = $data['preventSlugTranslation'] ?? null; $newOrder->includeTmFiles = $data['includeTmFiles'] ?? null; $newOrder->requestQuote = $data['requestQuote'] ?? null; $newOrder->targetSites = json_encode($data['targetSites'] ?? ''); @@ -936,6 +942,7 @@ public function actionUpdateOrder() $order->targetSites = json_encode($targetSites); $order->trackChanges = Craft::$app->getRequest()->getBodyParam('trackChanges'); $order->trackTargetChanges = Craft::$app->getRequest()->getBodyParam('trackTargetChanges'); + $order->preventSlugTranslation = Craft::$app->getRequest()->getBodyParam('preventSlugTranslation'); $order->includeTmFiles = Craft::$app->getRequest()->getBodyParam('includeTmFiles'); $translatorService->updateOrder($order); @@ -1222,11 +1229,12 @@ public function actionSaveOrderDraft() throw new HttpException(400, Translations::$plugin->translator ->translate('app', 'Source site is not supported')); } - + $orderId = Craft::$app->getRequest()->getBodyParam('id'); - $order = $this->service->getOrderById($orderId); - if (! $order->isPending()) { + if ($orderId && $this->service->getOrderById($orderId)->isPending()) { + $order = $this->service->getOrderById($orderId); + } else { $order = $this->service->makeNewOrder($sourceSite); $order->logActivity(Translations::$plugin->translator->translate('app', 'Order draft created')); } @@ -1271,6 +1279,7 @@ public function actionSaveOrderDraft() $order->title = $title; $order->trackChanges = Craft::$app->getRequest()->getBodyParam('trackChanges'); $order->trackTargetChanges = Craft::$app->getRequest()->getBodyParam('trackTargetChanges'); + $order->preventSlugTranslation = Craft::$app->getRequest()->getBodyParam('preventSlugTranslation'); $order->includeTmFiles = Craft::$app->getRequest()->getBodyParam('includeTmFiles'); $order->requestQuote = Craft::$app->getRequest()->getBodyParam('requestQuote'); $order->sourceSite = $sourceSite; diff --git a/src/controllers/SettingsController.php b/src/controllers/SettingsController.php index 6fc0e763..a41a9b27 100644 --- a/src/controllers/SettingsController.php +++ b/src/controllers/SettingsController.php @@ -232,10 +232,11 @@ public function actionConfigurationOptions() } $settings = Translations::getInstance()->settings; - $variables['chkDuplicateEntries'] = $settings->chkDuplicateEntries; - $variables['trackSourceChanges'] = $settings->trackSourceChanges; - $variables['trackTargetChanges'] = $settings->trackTargetChanges; - $variables['apiLogging'] = $settings->apiLogging; + $variables['chkDuplicateEntries'] = $settings->chkDuplicateEntries ?? ''; + $variables['trackSourceChanges'] = $settings->trackSourceChanges ?? ''; + $variables['trackTargetChanges'] = $settings->trackTargetChanges ?? ''; + $variables['preventSlugTranslation'] = $settings->preventSlugTranslation ?? ''; + $variables['apiLogging'] = $settings->apiLogging ?? ''; $variables['uploadVolume'] = $settings->uploadVolume; $variables['twigSearchFilterSingleQuote'] = !empty($settings->twigSearchFilterSingleQuote) ? $settings->twigSearchFilterSingleQuote : ""; $variables['twigSearchFilterDoubleQuote'] = !empty($settings->twigSearchFilterDoubleQuote) ? $settings->twigSearchFilterDoubleQuote : ""; @@ -244,10 +245,10 @@ public function actionConfigurationOptions() $allVolumes = Craft::$app->getVolumes()->getAllVolumes(); $variables['volumeOptions'] = array_map(function (Volume $volume) { - return [ - 'label' => $volume->name, - 'value' => $volume->id, - ]; + return [ + 'label' => $volume->name, + 'value' => $volume->id, + ]; }, $allVolumes); // Add default temp uploads option @@ -270,6 +271,7 @@ public function actionSaveConfigurationOptions() $duplicateEntries = $request->getParam('chkDuplicateEntries'); $trackSourceChanges = $request->getParam('trackSourceChanges'); $trackTargetChanges = $request->getParam('trackTargetChanges'); + $preventSlugTranslation = $request->getParam('preventSlugTranslation'); $apiLogging = $request->getParam('apiLogging'); $selectedVolume = $request->getParam('uploadVolume'); $twigSearchFilterSingleQuote = $request->getParam('twigSearchFilterSingleQuote'); @@ -285,6 +287,7 @@ public function actionSaveConfigurationOptions() 'chkDuplicateEntries' => $duplicateEntries, 'trackSourceChanges' => $trackSourceChanges, 'trackTargetChanges' => $trackTargetChanges, + 'preventSlugTranslation' => $preventSlugTranslation, 'apiLogging' => $apiLogging, 'uploadVolume' => $selectedVolume, 'twigSearchFilterSingleQuote' => $twigSearchFilterSingleQuote, diff --git a/src/elements/Order.php b/src/elements/Order.php index 47c416de..9b77cd62 100644 --- a/src/elements/Order.php +++ b/src/elements/Order.php @@ -83,6 +83,8 @@ class Order extends Element public $includeTmFiles; + public $preventSlugTranslation; + public $asynchronousPublishing; public $requestQuote; @@ -765,6 +767,13 @@ public function shouldTrackTargetContent() return $this->trackTargetChanges; } + public function shouldPreventSlugTranslation() + { + if (! $this->id) return Translations::getInstance()->settings->preventSlugTranslation; + + return $this->preventSlugTranslation; + } + /** * Check if the order should be processed using queue */ @@ -842,6 +851,11 @@ public function isPublished() { return $this->status === Constants::ORDER_STATUS_PUBLISHED; } + + public function isSlugTranslatable() + { + return !$this->preventSlugTranslation; + } public function requestQuote() { @@ -890,6 +904,7 @@ public function afterSave(bool $isNew): void $record->tags = $this->tags; $record->trackChanges = $this->trackChanges; $record->trackTargetChanges = $this->trackTargetChanges; + $record->preventSlugTranslation = $this->preventSlugTranslation; $record->includeTmFiles = $this->includeTmFiles; $record->requestQuote = $this->requestQuote; diff --git a/src/migrations/Install.php b/src/migrations/Install.php index ca2eb8b8..da7e2458 100644 --- a/src/migrations/Install.php +++ b/src/migrations/Install.php @@ -159,6 +159,7 @@ protected function createTables() 'trackChanges' => $this->integer()->defaultValue(0), 'includeTmFiles' => $this->integer()->defaultValue(0), 'trackTargetChanges' => $this->integer()->defaultValue(0), + 'preventSlugTranslation' => $this->integer()->defaultValue(0), 'asynchronousPublishing' => $this->integer()->defaultValue(0), 'requestQuote' => $this->integer()->defaultValue(0), 'dateCreated' => $this->dateTime()->notNull(), diff --git a/src/migrations/m230503_053114_add_prevent_slug_translation_column_to_orders_table.php b/src/migrations/m230503_053114_add_prevent_slug_translation_column_to_orders_table.php new file mode 100644 index 00000000..9fd7e3cf --- /dev/null +++ b/src/migrations/m230503_053114_add_prevent_slug_translation_column_to_orders_table.php @@ -0,0 +1,31 @@ +addColumn(Constants::TABLE_ORDERS, 'preventSlugTranslation', $this->integer()->defaultValue(0)->after('trackTargetChanges')); + + return true; + } + + /** + * @inheritdoc + */ + public function safeDown(): bool + { + $this->dropColumn(Constants::TABLE_ORDERS, 'preventSlugTranslation'); + return true; + } +} diff --git a/src/models/Settings.php b/src/models/Settings.php index 72fa7ba5..9f49573e 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -25,6 +25,8 @@ class Settings extends Model public $trackTargetChanges; + public $preventSlugTranslation; + public $apiLogging; public $twigSearchFilterSingleQuote = ""; diff --git a/src/services/ElementToFileConverter.php b/src/services/ElementToFileConverter.php index accbc9ff..6ebe5760 100644 --- a/src/services/ElementToFileConverter.php +++ b/src/services/ElementToFileConverter.php @@ -46,7 +46,7 @@ public function toXml(Element $element, $draftId, $sourceSite, $targetSite, $pre $body = $xml->appendChild($dom->createElement('body')); - foreach (Translations::$plugin->elementTranslator->toTranslationSource($element, $sourceSite) as $key => $value) { + foreach (Translations::$plugin->elementTranslator->toTranslationSource($element, $sourceSite, $orderId) as $key => $value) { $translation = $dom->createElement('content'); $translation->setAttribute('resname', $key); @@ -81,7 +81,8 @@ public function toJson(Element $element, $sourceSite, $targetSite, $wordCount, $ foreach ( Translations::$plugin->elementTranslator->toTranslationSource( $element, - $sourceSite + $sourceSite, + $orderId ) as $key => $value ) { $file['content'][$key] = $value; @@ -110,7 +111,8 @@ public function toCsv(Element $element, $sourceSite, $targetSite, $wordCount, $o foreach ( Translations::$plugin->elementTranslator->toTranslationSource( $element, - $sourceSite + $sourceSite, + $orderId ) as $key => $value ) { $headers .= ",\"$key\""; @@ -244,15 +246,15 @@ public function getElementIdFromData($content, $extension) { * @return string */ private function reportXmlErrors() { - $errors = array(); - $libErros = libxml_get_errors(); - - $msg = false; - if ($libErros && isset($libErros[0])) - { - $msg = $libErros[0]->code . ": " .$libErros[0]->message; - } - return $msg; + $errors = array(); + $libErros = libxml_get_errors(); + + $msg = false; + if ($libErros && isset($libErros[0])) + { + $msg = $libErros[0]->code . ": " .$libErros[0]->message; + } + return $msg; } public function csvToJson($file_content) diff --git a/src/services/ElementTranslator.php b/src/services/ElementTranslator.php index 06d8dd89..e2437c9e 100644 --- a/src/services/ElementTranslator.php +++ b/src/services/ElementTranslator.php @@ -21,10 +21,11 @@ use acclaro\translations\Translations; use craft\commerce\elements\Product; use craft\fields\Color; +use acclaro\translations\services\repository\OrderRepository; class ElementTranslator { - public function toTranslationSource(Element $element, $sourceSite=null) + public function toTranslationSource(Element $element, $sourceSite = null, $orderId = null) { $source = array(); @@ -33,9 +34,17 @@ public function toTranslationSource(Element $element, $sourceSite=null) $source['title'] = $element->title; } if ($element->slug) { - $source['slug'] = $element->slug; + switch (true) { + case ($orderId): + $order = (new OrderRepository())->getOrderById($orderId); + if ($order && !$order->isSlugTranslatable()) { + break; + } + default: + $source['slug'] = $element->slug; + } } - + } foreach ($element->getFieldLayout()->getCustomFields() as $layoutField) { diff --git a/src/services/fieldtranslator/AssetsFieldTranslator.php b/src/services/fieldtranslator/AssetsFieldTranslator.php index e75a6c53..8c38b631 100644 --- a/src/services/fieldtranslator/AssetsFieldTranslator.php +++ b/src/services/fieldtranslator/AssetsFieldTranslator.php @@ -29,9 +29,11 @@ public function toTranslationSource(ElementTranslator $elementTranslator, Elemen { foreach ($blocks as $block) { - $source[sprintf('%s.%s.%s', $field->handle, $block->id, 'title')] = $block->title; - $element = Craft::$app->assets->getAssetById($block->id, $sourceSite); + if ($element->getIsTitleTranslatable()) { + $source[sprintf('%s.%s.%s', $field->handle, $block->id, 'title')] = $block->title; + } + foreach ($element->getFieldLayout()->getCustomFields() as $layoutField) { $assetField = Craft::$app->fields->getFieldById($layoutField->id); $fieldSource = $elementTranslator->fieldToTranslationSource($element, $assetField, $sourceSite); diff --git a/src/services/repository/FileRepository.php b/src/services/repository/FileRepository.php index 6b5911e1..cd0838c7 100644 --- a/src/services/repository/FileRepository.php +++ b/src/services/repository/FileRepository.php @@ -481,7 +481,7 @@ public function checkTmMisalignments($file) $converter = Translations::$plugin->elementToFileConverter; - $currentContent = Translations::$plugin->elementTranslator->toTranslationSource($element, $sourceSite); + $currentContent = Translations::$plugin->elementTranslator->toTranslationSource($element, $sourceSite, $file->orderId); $currentContent = json_encode(array_map("strval", array_values($currentContent))); $sourceContent = json_decode($converter->xmlToJson($source), true); @@ -621,7 +621,8 @@ public function createReferenceData(array $data, $meta, $forDownload = true) $target = Translations::$plugin->elementTranslator->toTranslationSource( $data['targetElement'], - $data['targetElementSite'] + $data['targetElementSite'], + $meta['orderId'] ); $tmContent = ''; diff --git a/src/templates/_components/_forms/order-entries-table.twig b/src/templates/_components/_forms/order-entries-table.twig index 2988675a..d5654459 100644 --- a/src/templates/_components/_forms/order-entries-table.twig +++ b/src/templates/_components/_forms/order-entries-table.twig @@ -48,7 +48,7 @@ {% set entryPreviewSettings = order.entryPreviewSettings(element) %}
\ + Prevent\'s the translation of slug fields for the entries in this order.
'|t('app'), + id: "preventSlugTranslation", + name: "preventSlugTranslation", + class: "noClick", + on: shouldPreventSlugTranslation is defined ? shouldPreventSlugTranslation : order.shouldPreventSlugTranslation + }) }} +\ Include translation memory alignment files with order submission to prevent overwriting existing content edits.
'|t('app'), @@ -217,21 +238,5 @@Creates a seprate translation draft \ - for each target language that can be published independently.
'|t - (tag('button', { - type: 'button', - id: 'expand-status-btn', - class: ['btn'], - data: { - icon: 'ellipsis', - }, - })), - id: "asynchronousPublishing", - name: "asynchronousPublishing", - on: order.asynchronousPublishing - }) }} #}This plugin is made available by Acclaro. Any usage of it on a public site requires that the site owners have purchased the plugin either from Acclaro or the Craft plugin store.
diff --git a/src/templates/settings/configuration-options.twig b/src/templates/settings/configuration-options.twig index e76eb349..d28cea86 100644 --- a/src/templates/settings/configuration-options.twig +++ b/src/templates/settings/configuration-options.twig @@ -29,6 +29,7 @@ 'chkDuplicateEntries': chkDuplicateEntries, 'trackSourceChanges': trackSourceChanges, 'trackTargetChanges': trackTargetChanges, + 'preventSlugTranslation': preventSlugTranslation, 'apiLogging': apiLogging, }, }) }} @@ -60,6 +61,14 @@ on: trackTargetChanges, }) }} + {{ forms.lightswitchField({ + label: "Prevent slug translations by default"|t('app'), + instructions: "Enables the \"Prevent slug translations\" settings by default on new submission."|t('app'), + id: 'preventSlugTranslation', + name: 'preventSlugTranslation', + on: preventSlugTranslation, + }) }} +