Skip to content

Commit

Permalink
Release/3.2.6
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bhupeshappfoster committed May 26, 2023
1 parent cd07af1 commit 4cf145a
Show file tree
Hide file tree
Showing 20 changed files with 154 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .craftplugin
Original file line number Diff line number Diff line change
@@ -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/",
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/assetbundles/src/js/OrderDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -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[]"]');
Expand Down Expand Up @@ -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

Expand Down
15 changes: 12 additions & 3 deletions src/controllers/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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'] ?? '');
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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'));
}
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 11 additions & 8 deletions src/controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 : "";
Expand All @@ -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
Expand All @@ -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');
Expand All @@ -285,6 +287,7 @@ public function actionSaveConfigurationOptions()
'chkDuplicateEntries' => $duplicateEntries,
'trackSourceChanges' => $trackSourceChanges,
'trackTargetChanges' => $trackTargetChanges,
'preventSlugTranslation' => $preventSlugTranslation,
'apiLogging' => $apiLogging,
'uploadVolume' => $selectedVolume,
'twigSearchFilterSingleQuote' => $twigSearchFilterSingleQuote,
Expand Down
15 changes: 15 additions & 0 deletions src/elements/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class Order extends Element

public $includeTmFiles;

public $preventSlugTranslation;

public $asynchronousPublishing;

public $requestQuote;
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -842,6 +851,11 @@ public function isPublished()
{
return $this->status === Constants::ORDER_STATUS_PUBLISHED;
}

public function isSlugTranslatable()
{
return !$this->preventSlugTranslation;
}

public function requestQuote()
{
Expand Down Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/migrations/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace acclaro\translations\migrations;

use craft\db\Migration;
use acclaro\translations\Constants;

/**
* m230503_053114_add_prevent_slug_translation_column_to_orders_table migration.
*/
class m230503_053114_add_prevent_slug_translation_column_to_orders_table extends Migration
{
/**
* @inheritdoc
*/
public function safeUp()
{
$this->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;
}
}
2 changes: 2 additions & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Settings extends Model

public $trackTargetChanges;

public $preventSlugTranslation;

public $apiLogging;

public $twigSearchFilterSingleQuote = "";
Expand Down
26 changes: 14 additions & 12 deletions src/services/ElementToFileConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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\"";
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions src/services/ElementTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions src/services/fieldtranslator/AssetsFieldTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/services/repository/FileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 = '';

Expand Down
2 changes: 1 addition & 1 deletion src/templates/_components/_forms/order-entries-table.twig
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
{% set entryPreviewSettings = order.entryPreviewSettings(element) %}
<div id="{{ entryPreviewSettings['id'] }}">
<div class="elements">
<div class="element small" title="{{ element.uiLabel ~" - " ~siteObjects[order.sourceSite].name }}">
<div class="element flex" title="{{ element.uiLabel ~" - " ~siteObjects[order.sourceSite].name }}">
<div class="label" data-id="{{ element.id }}" data-editable="" data-site-id={{ order.sourceSite }} {% if entryPreviewSettings["draftId"] is defined %} data-draft-id="{{ entryPreviewSettings["draftId"] }}" {% endif %}>
<span class="title text-link">{{ element.uiLabel }}</span>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/templates/_components/_forms/order-files-table.twig
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
{% else %}
<div id="{{ "filePreview-"~ file.id }}">
<div class="elements">
<div class="element small" title="{{ file.uiLabel ~" - " ~siteObjects[file.targetSite].name }}">
<div class="element flex" title="{{ file.uiLabel ~" - " ~siteObjects[file.targetSite].name }}">
<div class="label" data-id="{{ file.elementId }}" data-editable="" data-site-id={{ file.targetSite }} {% if file.isComplete or element.isDraft %} data-draft-id={{ file.isComplete ? file.draftId : element.draftId }} {% endif %}>
<span class="title text-link">{{ file.uiLabel }}</span>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/templates/_components/app-info.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% set licenseStatus = craft.app.plugins.getPluginLicenseKeyStatus('translations') %}
{% set pluginHandle = constant('acclaro\\translations\\Constants::PLUGIN_HANDLE') %}
{% set licenseStatus = craft.app.plugins.getPluginInfo(pluginHandle)['licenseKeyStatus']|default(null) %}
{% set edition = (licenseStatus == 'valid') ? 'Paid' : 'Free trial' %}
{% set emailSubject = 'Hello Acclaro' %}
{% set emailBody = 'I’m interested in learning more about your professional translation services and how you can help with the launch of global Craft sites.%0D%0A%0D%0AThank you,%0D%0AYour Name%0D%0AYour Company%0D%0AYour Phone Number' %}
Expand Down
Loading

0 comments on commit 4cf145a

Please sign in to comment.