Skip to content

Commit

Permalink
Merge pull request #354 from AcclaroInc/release/2.2.1
Browse files Browse the repository at this point in the history
Release/2.2.1
  • Loading branch information
sidedwards authored Jun 24, 2022
2 parents 1cbda9f + 2405edf commit cb4a714
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 36 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": "2.2.0",
"pluginVersion": "2.2.1",
"pluginAuthorName": "Acclaro",
"pluginVendorName": "Acclaro",
"pluginAuthorUrl": "http://www.acclaro.com/",
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ 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/).

## 2.2.1 - 2022-06-24

### Fixed

- TM alignment error parsing special characters ([AcclaroInc/#483](https://github.com/AcclaroInc/pm-craft-translations/issues/483))
- Track target content notice bug ([AcclaroInc/#484](https://github.com/AcclaroInc/pm-craft-translations/issues/484))
- TM alignment file export bug ([AcclaroInc/485](https://github.com/AcclaroInc/pm-craft-translations/issues/485))

### Updated

- `craftcms/cms` minimum version from `3.7.33` to `3.7.36` due to dependency vulnerabilities
- `guzzlehttp/guzzle` minimum version from `6.5.7` to `6.5.8` due to dependency vulnerabilities

## 2.2.0 - 2022-06-21

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
}
],
"require": {
"craftcms/cms": "^3.7.33",
"guzzlehttp/guzzle": "^6.5.7|^7.0",
"craftcms/cms": "^3.7.36",
"guzzlehttp/guzzle": "^6.5.8|^7.0",
"php": ">=7.2.0",
"sebastian/diff": "^3.0",
"composer/composer": "^2.1.9",
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/FilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public function actionCreateExportZip()
Craft::error( '['. __METHOD__ .'] There was an error adding the file '.$fileName.' to the zip: '.$zipName, 'translations' );
}

if ($hasMisalignment) {
/** Check if entry exists in target site for reference comparison */
if ($hasMisalignment && Translations::$plugin->elementRepository->getElementById($file->elementId, $file->targetSite)) {
$tmFile = $file->getTmMisalignmentFile();
$fileName = $tmFile['fileName'];

Expand Down
8 changes: 5 additions & 3 deletions src/models/FileModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@ public function getElement($isApplied = null)

public function hasTmMisalignments($ignoreReference = false)
{
if ($this->isModified() || $this->isPublished()) return false;

// Reference or miss alignment can only be check if source entry exists in given target site
if (!Craft::$app->elements->getElementById($this->elementId, null, $this->targetSite)) {
return false;
Expand All @@ -236,7 +234,11 @@ public function hasTmMisalignments($ignoreReference = false)
return $this->_service->isReferenceChanged($this);
}

return $this->_service->checkTmMisalignments($this);
if ($ignoreReference || $this->isNew() || $this->isComplete()) {
return $this->_service->checkTmMisalignments($this);
}

return false;
}

public function getTmMisalignmentFile()
Expand Down
6 changes: 3 additions & 3 deletions src/services/job/ImportFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function processJsonFile($asset, $file_content)
return $file->isModified() ? false : '';
}

if ($file->isComplete()) {
if ($file->isComplete() || $file->isPublished()) {
$file->reference = null;
}

Expand Down Expand Up @@ -321,7 +321,7 @@ public function processXmlFile($asset, $xml_content)
return $file->isModified() ? false : '';
}

if ($file->isComplete()) {
if ($file->isComplete() || $file->isPublished()) {
$file->reference = null;
}

Expand Down Expand Up @@ -428,7 +428,7 @@ public function processCsvFile($asset, $file_contents)
return $file->isModified() ? false : '';
}

if ($file->isComplete()) {
if ($file->isComplete() || $file->isPublished()) {
$file->reference = null;
}

Expand Down
38 changes: 12 additions & 26 deletions src/services/repository/FileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,28 +477,7 @@ public function isReferenceChanged($file)
{
$currentData = $file->getTmMisalignmentFile()['reference'];

$currentData = $this->getTargetFromReference($currentData);

return md5($currentData) !== md5($this->getTargetFromReference($file->reference));
}

/**
* Extracts and returns only data for target site as data might change for source entry after
* update source entry.
*
* @param string $referenceData
* @return string
*/
private function getTargetFromReference($referenceData)
{
$targetData = [];
$referenceData = preg_split('/[\\n]/', $referenceData);

foreach ($referenceData as $line) {
array_push($targetData, explode(',', $line)[2]);
}

return implode(',', $targetData);
return md5($currentData) !== md5($file->reference);
}

/**
Expand Down Expand Up @@ -554,7 +533,10 @@ public function createReferenceData(array $data, $ignoreCommon = true)
$sourceLanguage = Craft::$app->sites->getSiteById($data['sourceElementSite'])->language;
$targetLanguage = Craft::$app->sites->getSiteById($data['targetElementSite'])->language;

$tmContent = sprintf('"key","%s","%s"', $sourceLanguage, $targetLanguage);
$tmContent = [[$targetLanguage]];

if ($ignoreCommon)
$tmContent = sprintf('"key","%s","%s"', $sourceLanguage, $targetLanguage);

$source = json_decode(Translations::$plugin->elementToFileConverter->xmlToJson($data['sourceContent']), true)['content'] ?? [];

Expand All @@ -565,10 +547,14 @@ public function createReferenceData(array $data, $ignoreCommon = true)

foreach ($source as $key => $value) {
$targetValue = $target[$key] ?? '';
if ($ignoreCommon && $value === $targetValue) continue;
$tmContent .= "\n" . sprintf('"%s","%s","%s"', $key, $value, $targetValue);
if ($ignoreCommon) {
if ($value !== $targetValue)
$tmContent .= "\n" . sprintf('"%s","%s","%s"', $key, $value, $targetValue);
} else {
$tmContent[] = [$targetValue];
}
}

return $tmContent;
return $ignoreCommon ? $tmContent : json_encode($tmContent);
}
}

0 comments on commit cb4a714

Please sign in to comment.