Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/1.9.4 #132

Merged
merged 18 commits into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
e8af9c2
Fixed issue Order status not updating to Applied
shnsumit Jan 13, 2021
ba01dab
Disable the Publish Changes button within Entry detail screen
shnsumit Jan 14, 2021
4f60f12
Merge pull request #129 from AcclaroInc/bug/disable-default-draft-pub…
sidedwards Jan 14, 2021
2dac510
Merge pull request #128 from AcclaroInc/bug/order-status-not-updating
sidedwards Jan 14, 2021
7a7ff92
Removed duplicate variables
sidedwards Jan 14, 2021
fce2038
- `generateElementPreviewUrl()` logic for $siteId parameter
sidedwards Jan 14, 2021
be7bbe2
Merge branch 'bug/element-url-site-ids' into release/1.9.4
sidedwards Jan 14, 2021
ca62ff5
Specify siteId when generating element preview url
sidedwards Jan 15, 2021
46e7cad
Merge branch 'bug/element-url-site-ids' into release/1.9.4
sidedwards Jan 15, 2021
523b44e
Custom Twig RegEx Filters
shnsumit Jan 15, 2021
05c1c50
Add spinner icon to individual Apply Translation buttons
shnsumit Jan 15, 2021
a0ce357
Merge pull request #131 from AcclaroInc/feature/improve-draft-visual-…
sidedwards Jan 16, 2021
a2e5a11
Merge pull request #130 from AcclaroInc/feature/custom-twig-regex-fil…
sidedwards Jan 16, 2021
e6afaae
Added 'zh-Hans-CN' mapping to `SiteRepository.php`
sidedwards Jan 16, 2021
acfc84d
Merge branch 'feature/add-zh-Hans-CN-locale' into release/1.9.4
sidedwards Jan 16, 2021
8af1c75
Updated CHANGELOG and .craftplugin to v1.9.4
sidedwards Jan 18, 2021
461257f
Added target string position in configuration setting
shnsumit Jan 18, 2021
34b9454
Merge pull request #133 from AcclaroInc/feature/custom-twig-regex-fil…
sidedwards Jan 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "Easily launch and manage multilingual Craft websites without having to copy/paste content or manually track updates.",
"pluginVersion": "1.9.3",
"pluginVersion": "1.9.4",
"pluginAuthorName": "Acclaro",
"pluginVendorName": "Acclaro",
"pluginAuthorUrl": "http://www.acclaro.com/",
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ 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/).

## 1.9.4 - 2021-01-18

## Added
- Custom Twig RegEx Filters for Static Translations https://github.com/AcclaroInc/craft-translations/pull/130
- Spinner icon to individual "Apply Translation" buttons https://github.com/AcclaroInc/craft-translations/pull/131
- `zh-Hans-CN` mapping to `SiteRepository.php` https://github.com/AcclaroInc/craft-translations/commit/acfc84dde21318bfb04a4e8970680aed12021699

### Fixed
- [BUG] - Target Site draft preview URI structures https://github.com/AcclaroInc/craft-translations/commit/be7bbe219730e5586477729996c1c5ecad84055d
- [BUG] - Disable the "Publish Changes" button within Entry detail screen https://github.com/AcclaroInc/craft-translations/pull/129
- [BUG] - Order status not updating to "Applied" https://github.com/AcclaroInc/craft-translations/pull/128

## 1.9.3 - 2020-12-16

### Fixed
Expand Down
3 changes: 0 additions & 3 deletions src/Translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,6 @@ private function _onDeleteElement(Event $event)

$currentFile->status = 'canceled';

$element = Craft::$app->getElements()->getElementById($currentFile->elementId, null, $currentFile->targetSite);
$currentFile->previewUrl = Translations::$plugin->urlGenerator->generateElementPreviewUrl($element, $currentFile->targetSite);

$element = Craft::$app->getElements()->getElementById($currentFile->elementId, null, $currentFile->sourceSite);
$currentFile->previewUrl = Translations::$plugin->urlGenerator->generateElementPreviewUrl($element, $currentFile->targetSite);
$currentFile->source = Translations::$plugin->elementToXmlConverter->toXml(
Expand Down
15 changes: 10 additions & 5 deletions src/assetbundles/src/js/ApplyTranslations.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Craft.Translations.ApplyTranslations = {
init: function(draftId, file) {
// Disable default Craft updating
window.draftEditor.settings.canUpdateSource = false;
$("#main-form input[type='submit']").disable();
$("#main-form input[type='submit']").attr('disabled', true);
$("#publish-changes-btn-container :input[type='button']").disable();
$("#publish-changes-btn-container :input[type='button']").attr('disabled', true);

// Create the Apply Translations button
var $applyTranslationsContainer = document.createElement('div');
Expand Down Expand Up @@ -46,13 +46,18 @@ Craft.Translations.ApplyTranslations = {
// reactivate the button
$(this.$btn).enable();
$(this.$btn).attr('disabled', false);
$(this.$btn).on("click", function (e) {

$(this.$btn).one("click", function (e) {
e.preventDefault();
$(".apply-translations > a").addClass("disabled");
$(".apply-translations > a").html("");
$(".apply-translations .submit").width(122);
$(".apply-translations > a").toggleClass("spinner");

var fileData = {
fileId: file.id,
};

Craft.postActionRequest('translations/files/apply-translation-draft', fileData, function(response, textStatus) {
if (textStatus === 'success' && response.success) {
console.log(response.data);
Expand All @@ -68,4 +73,4 @@ Craft.Translations.ApplyTranslations = {
},
};

})(jQuery);
})(jQuery);
8 changes: 8 additions & 0 deletions src/assetbundles/src/js/OrderDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,14 @@ Craft.Translations.OrderDetail = {
// Add the diff html
document.getElementById("modal-body-entry").innerHTML = diffHtml;

$('#apply-translation').one('click', function(e) {
$(".apply-translation").addClass("disabled");
$(".apply-translation").prop("value", "");
$(".apply-translation").css('margin-right', 4);
$(".apply-translation").width(110);
$(".apply-translation").toggleClass("spinner");
});

$('#close-diff-modal-entry').on('click', function(e) {
e.preventDefault();
modal.hide();
Expand Down
6 changes: 6 additions & 0 deletions src/assetbundles/src/js/OrderEntries.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ Craft.Translations.OrderEntries = {
Craft.Translations.OrderEntries.togglePublishButton();
Craft.Translations.OrderEntries.toggleSelectAllCheckbox();
});
this.$publishSelectedBtn.one('click', function (e) {
$(".translations-publish-selected-btn").addClass("disabled");
$(".translations-publish-selected-btn").prop("value", "");
$(".translations-publish-selected-btn").width(160);
$(".translations-publish-selected-btn").toggleClass("spinner");
});
}
};

Expand Down
7 changes: 2 additions & 5 deletions src/controllers/FilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,14 +468,11 @@ public function actionApplyTranslationDraft()
$publishedFilesCount = 0;

foreach ($files as $key => $f) {
if ($f->status !== 'complete') {
continue;
if ($f->status === 'published') {
$publishedFilesCount++;
}

$publishedFilesCount++;
}


if ($publishedFilesCount === $filesCount) {
$order->status = 'published';
}
Expand Down
13 changes: 10 additions & 3 deletions src/controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,12 @@ public function actionConfigurationOptions()
return;
}

$variables['chkDuplicateEntries'] = Translations::getInstance()->settings->chkDuplicateEntries;
$variables['uploadVolume'] = Translations::getInstance()->settings->uploadVolume;
$settings = Translations::getInstance()->settings;
$variables['chkDuplicateEntries'] = $settings->chkDuplicateEntries;
$variables['uploadVolume'] = $settings->uploadVolume;
$variables['twigSearchFilterSingleQuote'] = !empty($settings->twigSearchFilterSingleQuote) ? $settings->twigSearchFilterSingleQuote : "";
$variables['twigSearchFilterDoubleQuote'] = !empty($settings->twigSearchFilterDoubleQuote) ? $settings->twigSearchFilterDoubleQuote : "";
$variables['targetStringPosition'] = !empty($settings->targetStringPosition) ? $settings->targetStringPosition : "";

$allVolumes = Craft::$app->getVolumes()->getAllVolumes();

Expand Down Expand Up @@ -264,12 +268,15 @@ public function actionSaveConfigurationOptions()
$request = Craft::$app->getRequest();
$duplicateEntries = $request->getParam('chkDuplicateEntries');
$selectedVolume = $request->getParam('uploadVolume');
$twigSearchFilterSingleQuote = $request->getParam('twigSearchFilterSingleQuote');
$twigSearchFilterDoubleQuote = $request->getParam('twigSearchFilterDoubleQuote');
$targetStringPosition = $request->getParam('targetStringPosition');

try {

$pluginService = Craft::$app->getPlugins();
$plugin = $pluginService->getPlugin('translations');
if (!$pluginService->savePluginSettings($plugin, ['chkDuplicateEntries' => $duplicateEntries, 'uploadVolume' => $selectedVolume])) {
if (!$pluginService->savePluginSettings($plugin, ['chkDuplicateEntries' => $duplicateEntries, 'uploadVolume' => $selectedVolume, 'twigSearchFilterSingleQuote' => $twigSearchFilterSingleQuote, 'twigSearchFilterDoubleQuote' => $twigSearchFilterDoubleQuote, 'targetStringPosition' => $targetStringPosition])) {
Craft::$app->getSession()->setError(Translations::$plugin->translator->translate('app', 'Unable to save setting.'));
} else {
Craft::$app->getSession()->setNotice(Translations::$plugin->translator->translate('app', 'Setting saved.'));
Expand Down
6 changes: 6 additions & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class Settings extends Model
{
public $chkDuplicateEntries = true;

public $twigSearchFilterSingleQuote = "";

public $twigSearchFilterDoubleQuote = "";

public $targetStringPosition = "";

/** @var int The Volume ID where uploads will be saved */
public $uploadVolume = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/services/ElementToXmlConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function toXml(Element $element, $draftId = 0, $sourceSite = null, $targe
$sites->setAttribute('target-site', $targetSite);
$langs->setAttribute('source-language', Craft::$app->sites->getSiteById($sourceSite)->language);
$langs->setAttribute('target-language', (Craft::$app->sites->getSiteById($targetSite)) ? Craft::$app->sites->getSiteById($targetSite)->language : 'deleted');
$original->setAttribute('url', Translations::$plugin->urlGenerator->generateElementPreviewUrl($element, $targetSite));
$original->setAttribute('url', Translations::$plugin->urlGenerator->generateElementPreviewUrl($element));
$preview->setAttribute('url', $previewUrl);

$elementIdMeta = $head->appendChild($dom->createElement('meta'));
Expand Down
8 changes: 5 additions & 3 deletions src/services/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function generateCpUrl($path)
return Translations::$plugin->urlHelper->cpUrl($path);
}

public function generateElementPreviewUrl(Element $element, $targetSite)
public function generateElementPreviewUrl(Element $element, $siteId = null)
{
$params = array();

Expand All @@ -119,11 +119,13 @@ public function generateElementPreviewUrl(Element $element, $targetSite)
if ($className === Entry::class && !$element->getIsDraft()) {
$previewUrl = $element->getUrl();
} else {
$element = Craft::$app->getElements()->getElementById($element->sourceId, null, $siteId);

$route = [
'preview/preview', [
'elementType' => $className,
'sourceId' => $element->sourceId,
'siteId' => $element->siteId,
'siteId' => $siteId ? $siteId : $element->siteId,
'draftId' => $element->draftId,
'revisionId' => $element->revisionId
]
Expand All @@ -142,7 +144,7 @@ public function generateElementPreviewUrl(Element $element, $targetSite)
$previewUrl = '';
}
}

return $previewUrl;
}
}
1 change: 1 addition & 0 deletions src/services/repository/SiteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class SiteRepository
'zh-tw' => 'zh-TW', //Chinese (Traditional)
'zh-hans' => 'zh-CN', //Chinese (Simplified)
'zh-hant' => 'zh-TW', //Chinese (Traditional)
'zh-hans-cn' => 'zh-CN', //Chinese (Simplified)
'nl-nl' => 'nl', //Dutch (Netherlands)
'da-dk' => 'da', //Danish (Denmark)
'en' => 'en-us', //English
Expand Down
18 changes: 14 additions & 4 deletions src/services/repository/StaticTranslationsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Exception;
use craft\helpers\FileHelper;
use craft\helpers\ElementHelper;
use acclaro\translations\Translations;
use craft\elements\db\ElementQueryInterface;
use acclaro\translations\elements\StaticTranslations;

Expand Down Expand Up @@ -137,6 +138,16 @@ private function getFileStrings($path, $file, ElementQueryInterface $query, $cat
* @return array
*/
public function getExpressions($ext) {
$settings = Translations::getInstance()->settings;
if(!empty($settings->twigSearchFilterSingleQuote)) {
$twigSearchFilterSingleQuote = $settings->twigSearchFilterSingleQuote;
$twigSearchFilterDoubleQuote = $settings->twigSearchFilterDoubleQuote;
$targetStringPosition = $settings->targetStringPosition;
} else {
$twigSearchFilterSingleQuote = '/\'((?:[^\']|\\\\\')*)\'\s*\|\s*t(?:ranslate)?\b/';
$twigSearchFilterDoubleQuote = '/"((?:[^"]|\\\\")*)"\s*\|\s*t(?:ranslate)?\b/';
$targetStringPosition = 1;
}

$exp = [];
switch ($ext) {
Expand All @@ -154,10 +165,9 @@ public function getExpressions($ext) {
case 'atom':
case 'rss':
$exp = [
'position' => '1',
'position' => $targetStringPosition,
'regex' => [
'/\'((?:[^\']|\\\\\')*)\'\s*\|\s*t(?:ranslate)?\b/',
'/"((?:[^"]|\\\\")*)"\s*\|\s*t(?:ranslate)?\b/',
$twigSearchFilterSingleQuote, $twigSearchFilterDoubleQuote
]
];
break;
Expand Down Expand Up @@ -205,4 +215,4 @@ public function set($lang, array $fileContent)

return true;
}
}
}
31 changes: 30 additions & 1 deletion src/templates/settings/configuration-options.twig
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,35 @@
toggle: true
}) }}

<h3>{{ "Static Translations"|t('app') }}</h3>

{{ forms.textField({
label: "Twig search filter (single quote)"|t('app'),
placeholder: "Twig search filter (single quote)"|t('app'),
id: 'twigSearchFilterSingleQuote',
name: 'twigSearchFilterSingleQuote',
value: twigSearchFilterSingleQuote ?? '',
size: '40',
}) }}

{{ forms.textField({
label: "Twig search filter (double quote)"|t('app'),
placeholder: "Twig search filter (double quote)"|t('app'),
id: 'twigSearchFilterDoubleQuote',
name: 'twigSearchFilterDoubleQuote',
value: twigSearchFilterDoubleQuote ?? '',
size: '40',
}) }}

{{ forms.textField({
label: "Target String Position"|t('app'),
placeholder: "Target String Position"|t('app'),
id: 'targetStringPosition',
name: 'targetStringPosition',
value: targetStringPosition ?? '',
size: '40',
}) }}

<div class="buttons">
<input type="submit" id="save-configuration" class="btn" value="{{ "Save"|t('app') }}" />
</div>
Expand All @@ -50,4 +79,4 @@
$('#save-configuration').toggleClass('submit');
});
});
{% endjs %}
{% endjs %}