Skip to content

Commit a639f83

Browse files
committed
[BUGFIX] Make copy mode work again
The newly added structure with LocalizationModes registered as configurable modes through PHP instead of the hard-coded Localization used the `LocalizationController::ACTION_*` constants for detecting the EventListener being responsible for a translation mode. As the JavaScript identifier was taken for the comparison and the identifier was named `copy`, but the compare-to is named `copyFromLanguage`, the condition skipped the EventListener instead of building the command map for the DataHandler to work. Fixes #11
1 parent 72ab659 commit a639f83

File tree

5 files changed

+97
-10
lines changed

5 files changed

+97
-10
lines changed

Classes/EventListener/ProvideDefaultTypo3LocalizationModesEventListener.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace WebVision\Deepl\Base\EventListener;
66

7+
use TYPO3\CMS\Backend\Controller\Page\LocalizationController;
78
use TYPO3\CMS\Core\Utility\MathUtility;
89
use WebVision\Deepl\Base\Event\GetLocalizationModesEvent;
910
use WebVision\Deepl\Base\Localization\LocalizationMode;
@@ -24,22 +25,22 @@ public function __invoke(GetLocalizationModesEvent $event): void
2425
$modes = [];
2526
if ($this->allowTranslate($event)) {
2627
$modes[] = new LocalizationMode(
27-
identifier: 'localize',
28+
identifier: LocalizationController::ACTION_LOCALIZE,
2829
title: $event->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.translate'),
2930
description: $event->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.translate'),
3031
icon: 'actions-localize',
31-
before: ['copy'],
32+
before: [LocalizationController::ACTION_COPY],
3233
after: [],
3334
);
3435
}
3536
if ($this->allowCopy($event)) {
3637
$modes[] = new LocalizationMode(
37-
identifier: 'copy',
38+
identifier: LocalizationController::ACTION_COPY,
3839
title: $event->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.copy'),
3940
description: $event->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.copy'),
4041
icon: 'actions-edit-copy',
4142
before: [],
42-
after: ['localize'],
43+
after: [LocalizationController::ACTION_LOCALIZE],
4344
);
4445
}
4546

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"tt_content",
2+
,"uid","pid","CType","sys_language_uid","header","l18n_parent","l10n_source"
3+
,1,3,"header",0,"Content header",0,0
4+
,2,3,"header",1,"[Translate to Deutsch:] Content header",0,1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"tt_content",
2+
,"uid","pid","CType","sys_language_uid","header","l18n_parent","l10n_source"
3+
,1,3,"header",0,"Content header",0,0
4+
,2,3,"header",1,"[Translate to Deutsch:] Content header",1,1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"pages",
2+
,"uid","pid","doktype","sys_language_uid","l10n_parent","slug","title","TSconfig",
3+
,1,0,1,0,0,"/","site 1","",
4+
,2,0,1,1,1,"/","Seite 1","",
5+
,3,1,1,0,0,"/home","Home","",
6+
,4,1,1,1,3,"/start","Start","",
7+
"tt_content",
8+
,"uid","pid","CType","sys_language_uid","header"
9+
,1,3,"header",0,"Content header"
10+
"be_users",
11+
,"uid","pid","tstamp","username","password","admin","disable","starttime","endtime","options","crdate","workspace_perms","deleted","TSconfig","lastlogin","workspace_id"
12+
# The password is "password"
13+
,1,0,1366642540,"admin","$1$tCrlLajZ$C0sikFQQ3SWaFAZ1Me0Z/1",1,0,0,0,0,1366642540,1,0,,1371033743,0

Tests/Functional/Controller/Backend/LocalizationControllerTest.php

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
use SBUERK\TYPO3\Testing\SiteHandling\SiteBasedTestTrait;
1010
use SBUERK\TYPO3\Testing\TestCase\FunctionalTestCase;
1111
use TYPO3\CMS\Backend\Utility\BackendUtility;
12+
use TYPO3\CMS\Core\Http\ServerRequest;
1213
use TYPO3\CMS\Core\Localization\LanguageService;
14+
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
1315
use TYPO3\CMS\Core\Site\SiteFinder;
1416
use TYPO3\CMS\Core\Utility\GeneralUtility;
1517
use WebVision\Deepl\Base\Controller\Backend\LocalizationController;
@@ -52,12 +54,12 @@ public static function dispatchGetLocalizationModesEventReturnsExpectedDefaultMo
5254
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.translate',
5355
'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.translate',
5456
'icon' => 'actions-localize',
55-
'before' => ['copy'],
57+
'before' => ['copyFromLanguage'],
5658
'after' => [],
5759
'restrictedSourceLanguageIds' => null,
5860
],
5961
[
60-
'identifier' => 'copy',
62+
'identifier' => 'copyFromLanguage',
6163
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.copy',
6264
'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.copy',
6365
'icon' => 'actions-edit-copy',
@@ -79,12 +81,12 @@ public static function dispatchGetLocalizationModesEventReturnsExpectedDefaultMo
7981
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.translate',
8082
'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.translate',
8183
'icon' => 'actions-localize',
82-
'before' => ['copy'],
84+
'before' => ['copyFromLanguage'],
8385
'after' => [],
8486
'restrictedSourceLanguageIds' => null,
8587
],
8688
[
87-
'identifier' => 'copy',
89+
'identifier' => 'copyFromLanguage',
8890
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.copy',
8991
'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.copy',
9092
'icon' => 'actions-edit-copy',
@@ -114,7 +116,7 @@ public static function dispatchGetLocalizationModesEventReturnsExpectedDefaultMo
114116
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.translate',
115117
'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.translate',
116118
'icon' => 'actions-localize',
117-
'before' => ['copy'],
119+
'before' => ['copyFromLanguage'],
118120
'after' => [],
119121
'restrictedSourceLanguageIds' => null,
120122
],
@@ -128,7 +130,7 @@ public static function dispatchGetLocalizationModesEventReturnsExpectedDefaultMo
128130
'expectedModesJsonString' => \json_encode(
129131
[
130132
[
131-
'identifier' => 'copy',
133+
'identifier' => 'copyFromLanguage',
132134
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.copy',
133135
'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.copy',
134136
'icon' => 'actions-edit-copy',
@@ -187,6 +189,69 @@ public function dispatchGetLocalizationModesEventReturnsExpectedDefaultModesBase
187189
$this->assertSame($expectedModesJsonString, \json_encode($modes, JSON_THROW_ON_ERROR));
188190
}
189191

192+
public static function translationModesDataProvider(): \Generator
193+
{
194+
yield 'Translation mode "localize" works' => [
195+
'getParams' => [
196+
'pageId' => 3,
197+
'srcLanguageId' => 0,
198+
'destLanguageId' => 1,
199+
'action' => 'localize',
200+
'uidList' => [1],
201+
],
202+
'expectedFixture' => __DIR__ . '/Fixtures/TranslationModes/Result/localize.csv',
203+
];
204+
yield 'Translation mode "copy" works' => [
205+
'getParams' => [
206+
'pageId' => 3,
207+
'srcLanguageId' => 0,
208+
'destLanguageId' => 1,
209+
'action' => 'copyFromLanguage',
210+
'uidList' => [1],
211+
],
212+
'expectedFixture' => __DIR__ . '/Fixtures/TranslationModes/Result/copyToLanguage.csv',
213+
];
214+
}
215+
216+
/**
217+
* @param array{
218+
* pageId: int,
219+
* srcLanguageId: int,
220+
* destLanguageId: int,
221+
* action: string,
222+
* uidList: int[]
223+
* } $getParams
224+
*/
225+
#[DataProvider('translationModesDataProvider')]
226+
#[Test]
227+
public function translationModesWorkAsExpected(
228+
array $getParams,
229+
string $expectedFixture
230+
): void {
231+
$this->importCSVDataSet(__DIR__ . '/Fixtures/TranslationModes/TranslationModeSetup.csv');
232+
$this->writeSiteConfiguration(
233+
identifier: 'acme',
234+
site: $this->buildSiteConfiguration(
235+
rootPageId: 1,
236+
),
237+
languages: [
238+
$this->buildDefaultLanguageConfiguration('EN', '/'),
239+
$this->buildLanguageConfiguration('EN', '/eb/', ['EN'], 'strict'),
240+
$this->buildLanguageConfiguration('DE', '/de/', ['DE'], 'strict'),
241+
$this->buildLanguageConfiguration('FR', '/fr/', ['FR'], 'strict'),
242+
],
243+
);
244+
$this->setUpFrontendRootPage(1, [], []);
245+
$beUser = $this->setUpBackendUser(1);
246+
$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)
247+
->createFromUserPreferences($beUser);
248+
$request = (new ServerRequest('http://localhost/typo3/ajax/records/localize/process'))
249+
->withQueryParams($getParams);
250+
$response = $this->createSubject()->localizeRecords($request);
251+
$this->assertSame(200, $response->getStatusCode());
252+
$this->assertCSVDataSet($expectedFixture);
253+
}
254+
190255
private function createSubject(): LocalizationController
191256
{
192257
return $this->get(LocalizationController::class);

0 commit comments

Comments
 (0)