Skip to content

Commit

Permalink
Merge pull request #79 from lilt/3.x-slug-name-on-files
Browse files Browse the repository at this point in the history
Add slug to translation filename
  • Loading branch information
hadomskyi authored Feb 6, 2023
2 parents 67a5e2d + 7be037a commit e60f981
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 29 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ 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.3.0 - 2022-11-20
## 3.4.0 - 2023-02-06
### Added
- Entry slug name added to translation filenames

## 3.3.0 - 2023-01-27
### Added
- Priority for jobs from queue
- Background job for translation downloading
Expand All @@ -17,7 +21,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Entry version content provider
- Updating of translation connector ids

## 3.2.1 - 2022-11-20
## 3.2.1 - 2023-01-04
### Added
- Increase TTR for background jobs

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "lilt/craft-lilt-plugin",
"description": "The Lilt plugin makes it easy for you to send content to Lilt for translation right from within Craft CMS.",
"type": "craft-plugin",
"version": "3.3.0",
"version": "3.4.0",
"keywords": [
"craft",
"cms",
Expand Down
4 changes: 2 additions & 2 deletions e2e/cypress/support/flow/instant.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Cypress.Commands.add('instantFlow', ({
}, {
'name': 'srclang', 'values': ['en'],
}, {
'name': 'name', 'values': ['element_[\\d]+\\.json\\+html'],
'name': 'name', 'values': ['element_[\\d]+_.*\\.json\\+html'],
}, {
'name': 'due', 'values': [''],
}],
Expand Down Expand Up @@ -159,7 +159,7 @@ Cypress.Commands.add('instantFlow', ({
'createdAt': '2022-05-29T11:31:58',
'errorMsg': null,
'id': translationId,
'name': '777_element_' + 24 + '.json+html',
'name': '777_element_' + 24 + '_slug_for_' + language + '.json+html',
'status': 'mt_complete',
'trgLang': language,
'trgLocale': '',
Expand Down
2 changes: 1 addition & 1 deletion src/elements/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function getActionsHtml(): string
{
$dataSourceContent = '';
if (!empty($this->sourceContent)) {
$dataSourceContent = 'data-source-content="' . base64_encode($this->sourceContent);
$dataSourceContent = 'data-source-content="' . base64_encode($this->sourceContent) . '"';
}

return '
Expand Down
14 changes: 11 additions & 3 deletions src/services/handlers/SendJobToLiltConnectorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public function __invoke(Job $job): void
$draft
);

$slug = !empty($element->slug) ? $element->slug : 'no-slug-available';

$result = $this->createJobFile(
$content,
$versionId,
Expand All @@ -92,7 +94,8 @@ public function __invoke(Job $job): void
Craftliltplugin::getInstance()->languageMapper->getLanguagesBySiteIds(
[$targetSiteId]
),
null //TODO: $job->dueDate is not in use
null, //TODO: $job->dueDate is not in use
$slug
);

if (!$result) {
Expand Down Expand Up @@ -152,13 +155,18 @@ private function createJobFile(
int $jobId,
string $sourceLanguage,
array $targetSiteLanguages,
?DateTimeInterface $dueDate
?DateTimeInterface $dueDate,
string $slug
): bool {
$contentString = json_encode($content);

if (!empty($slug)) {
$slug = substr($slug, 0, 150);
}

return Craftliltplugin::getInstance()->connectorJobsFileRepository->addFileToJob(
$jobId,
'element_' . $entryId . '.json+html',
'element_' . $entryId . '_' . $slug . '.json+html',
$contentString,
$sourceLanguage,
$targetSiteLanguages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function findTranslationContentById(int $translationId): string

public function getElementIdFromTranslationResponse(TranslationResponse $translationResponse): int
{
$regExpr = '/\d+_element_(\d+).json\+html/';
$regExpr = '/\d+_element_(\d+)(_.*|)\.json\+html/';
preg_match($regExpr, $translationResponse->getName(), $matches);

if (!isset($matches[1])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function testSyncSuccess(IntegrationTester $I): void
'createdAt' => '2022-05-29T11:31:58',
'errorMsg' => null,
'id' => 703695,
'name' => '497058_element_505.json+html',
'name' => '497058_element_505_first-entry-user-1.json+html',
'status' => 'export_complete',
'trgLang' => 'es',
'trgLocale' => 'ES',
Expand All @@ -98,7 +98,7 @@ public function testSyncSuccess(IntegrationTester $I): void
'createdAt' => '2022-05-29T11:31:58',
'errorMsg' => null,
'id' => 703696,
'name' => '497058_element_505.json+html',
'name' => '497058_element_505_first-entry-user-1.json+html',
'status' => 'export_complete',
'trgLang' => 'de',
'trgLocale' => 'DE',
Expand All @@ -108,7 +108,7 @@ public function testSyncSuccess(IntegrationTester $I): void
'createdAt' => '2022-05-29T11:31:58',
'errorMsg' => null,
'id' => 703697,
'name' => '497058_element_505.json+html',
'name' => '497058_element_505_first-entry-user-1.json+html',
'status' => 'export_complete',
'trgLang' => 'ru',
'trgLocale' => 'RU',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function testRetrySuccess(IntegrationTester $I): void
. '&trglang=es-ES' .
'&due=',
urlencode(
sprintf('element_%d.json+html', $element->getId())
sprintf('element_%d_first-entry-user-1.json+html', $element->getId())
)
);
$expectedBody = ExpectedElementContent::getExpectedBody($element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private function getTranslationsResponseBody(
int $elementId,
string $status
): array {
$fileName = sprintf('497058_element_%d.json+html', $elementId);
$fileName = sprintf('497058_element_%d_first-entry-user-1.json+html', $elementId);

$translationsResponseBody = [
'limit' => 25,
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/modules/FetchJobStatusFromConnectorCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function testExecuteSuccessVerified(IntegrationTester $I): void
'createdAt' => '2022-05-29T11:31:58',
'errorMsg' => null,
'id' => 11111,
'name' => sprintf('497058_element_%d.json+html', $element->id),
'name' => sprintf('497058_element_%d_first-entry-user-1.json+html', $element->id),
'status' => 'export_complete',
'trgLang' => 'es',
'trgLocale' => 'ES',
Expand All @@ -86,7 +86,7 @@ public function testExecuteSuccessVerified(IntegrationTester $I): void
'createdAt' => '2022-05-29T11:31:58',
'errorMsg' => null,
'id' => 22222,
'name' => sprintf('497058_element_%d.json+html', $element->id),
'name' => sprintf('497058_element_%d_first-entry-user-1.json+html', $element->id),
'status' => 'export_complete',
'trgLang' => 'de',
'trgLocale' => 'DE',
Expand All @@ -96,7 +96,7 @@ public function testExecuteSuccessVerified(IntegrationTester $I): void
'createdAt' => '2022-05-29T11:31:58',
'errorMsg' => null,
'id' => 33333,
'name' => sprintf('497058_element_%d.json+html', $element->id),
'name' => sprintf('497058_element_%d_first-entry-user-1.json+html', $element->id),
'status' => 'export_complete',
'trgLang' => 'ru',
'trgLocale' => 'RU',
Expand Down Expand Up @@ -207,7 +207,7 @@ public function testExecuteSuccessInstant(IntegrationTester $I): void
'createdAt' => '2022-05-29T11:31:58',
'errorMsg' => null,
'id' => 11111,
'name' => sprintf('497058_element_%d.json+html', $element->id),
'name' => sprintf('497058_element_%d_first-entry-user-1.json+html', $element->id),
'status' => 'export_complete',
'trgLang' => 'es',
'trgLocale' => 'ES',
Expand All @@ -217,7 +217,7 @@ public function testExecuteSuccessInstant(IntegrationTester $I): void
'createdAt' => '2022-05-29T11:31:58',
'errorMsg' => null,
'id' => 22222,
'name' => sprintf('497058_element_%d.json+html', $element->id),
'name' => sprintf('497058_element_%d_first-entry-user-1.json+html', $element->id),
'status' => 'export_complete',
'trgLang' => 'de',
'trgLocale' => 'DE',
Expand All @@ -227,7 +227,7 @@ public function testExecuteSuccessInstant(IntegrationTester $I): void
'createdAt' => '2022-05-29T11:31:58',
'errorMsg' => null,
'id' => 33333,
'name' => sprintf('497058_element_%d.json+html', $element->id),
'name' => sprintf('497058_element_%d_first-entry-user-1.json+html', $element->id),
'status' => 'export_complete',
'trgLang' => 'ru',
'trgLocale' => 'RU',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ private function getTranslationsResponseBody(
int $elementId,
string $status
): array {
$fileName = sprintf('497058_element_%d.json+html', $elementId);
$fileName = sprintf('497058_element_%d_first-entry-user-1.json+html', $elementId);

$translationsResponseBody = [
'limit' => 25,
Expand Down Expand Up @@ -575,7 +575,7 @@ private function getTranslationsResponseBody(

private function getTranslationsResponseBodyOneFailed(int $elementId): array
{
$fileName = sprintf('497058_element_%d.json+html', $elementId);
$fileName = sprintf('497058_element_%d_first-entry-user-1.json+html', $elementId);

return [
'limit' => 25,
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/modules/SendJobToConnectorCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function testCreateJob(IntegrationTester $I): void
. '&trglang=de-DE'
. '&due=',
urlencode(
sprintf('element_%d.json+html', $elementToTranslate->getId())
sprintf('element_%d_first-entry-user-1.json+html', $elementToTranslate->getId())
)
);
$I->expectJobTranslationsRequest($expectedUrlDe, [], HttpCode::OK);
Expand All @@ -107,7 +107,7 @@ public function testCreateJob(IntegrationTester $I): void
. '&trglang=ru-RU'
. '&due=',
urlencode(
sprintf('element_%d.json+html', $elementToTranslate->getId())
sprintf('element_%d_first-entry-user-1.json+html', $elementToTranslate->getId())
)
);
$I->expectJobTranslationsRequest($expectedUrlRu, [], HttpCode::OK);
Expand All @@ -118,7 +118,7 @@ public function testCreateJob(IntegrationTester $I): void
. '&trglang=es-ES'
. '&due=',
urlencode(
sprintf('element_%d.json+html', $elementToTranslate->getId())
sprintf('element_%d_first-entry-user-1.json+html', $elementToTranslate->getId())
)
);
$I->expectJobTranslationsRequest($expectedUrlEs, [], HttpCode::OK);
Expand Down Expand Up @@ -317,7 +317,7 @@ public function testCreateJobWithUnexpectedStatusFromConnector(IntegrationTester
. '&trglang=de-DE'
. '&due=',
urlencode(
sprintf('element_%d.json+html', $element->getId())
sprintf('element_%d_first-entry-user-1.json+html', $element->getId())
)
);
$I->expectJobTranslationsRequest($expectedUrlDe, [], HttpCode::INTERNAL_SERVER_ERROR);
Expand All @@ -328,7 +328,7 @@ public function testCreateJobWithUnexpectedStatusFromConnector(IntegrationTester
. '&trglang=ru-RU'
. '&due=',
urlencode(
sprintf('element_%d.json+html', $element->getId())
sprintf('element_%d_first-entry-user-1.json+html', $element->getId())
)
);
$I->expectJobTranslationsRequest($expectedUrlRu, [], HttpCode::INTERNAL_SERVER_ERROR);
Expand All @@ -339,7 +339,7 @@ public function testCreateJobWithUnexpectedStatusFromConnector(IntegrationTester
. '&trglang=es-ES'
. '&due=',
urlencode(
sprintf('element_%d.json+html', $element->getId())
sprintf('element_%d_first-entry-user-1.json+html', $element->getId())
)
);
$I->expectJobTranslationsRequest($expectedUrlEs, [], HttpCode::INTERNAL_SERVER_ERROR);
Expand Down

0 comments on commit e60f981

Please sign in to comment.