Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace WebVision\Deepl\Base\EventListener;

use TYPO3\CMS\Backend\Controller\Page\LocalizationController;
use TYPO3\CMS\Core\Utility\MathUtility;
use WebVision\Deepl\Base\Event\GetLocalizationModesEvent;
use WebVision\Deepl\Base\Localization\LocalizationMode;
Expand All @@ -24,22 +25,22 @@ public function __invoke(GetLocalizationModesEvent $event): void
$modes = [];
if ($this->allowTranslate($event)) {
$modes[] = new LocalizationMode(
identifier: 'localize',
identifier: LocalizationController::ACTION_LOCALIZE,
title: $event->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.translate'),
description: $event->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.translate'),
icon: 'actions-localize',
before: ['copy'],
before: [LocalizationController::ACTION_COPY],
after: [],
);
}
if ($this->allowCopy($event)) {
$modes[] = new LocalizationMode(
identifier: 'copy',
identifier: LocalizationController::ACTION_COPY,
title: $event->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.copy'),
description: $event->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.copy'),
icon: 'actions-edit-copy',
before: [],
after: ['localize'],
after: [LocalizationController::ACTION_LOCALIZE],
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"tt_content",
,"uid","pid","CType","sys_language_uid","header","l18n_parent","l10n_source"
,1,3,"header",0,"Content header",0,0
,2,3,"header",1,"[Translate to Deutsch:] Content header",0,1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"tt_content",
,"uid","pid","CType","sys_language_uid","header","l18n_parent","l10n_source"
,1,3,"header",0,"Content header",0,0
,2,3,"header",1,"[Translate to Deutsch:] Content header",1,1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"pages",
,"uid","pid","doktype","sys_language_uid","l10n_parent","slug","title","TSconfig",
,1,0,1,0,0,"/","site 1","",
,2,0,1,1,1,"/","Seite 1","",
,3,1,1,0,0,"/home","Home","",
,4,1,1,1,3,"/start","Start","",
"tt_content",
,"uid","pid","CType","sys_language_uid","header"
,1,3,"header",0,"Content header"
"be_users",
,"uid","pid","tstamp","username","password","admin","disable","starttime","endtime","options","crdate","workspace_perms","deleted","TSconfig","lastlogin","workspace_id"
# The password is "password"
,1,0,1366642540,"admin","$1$tCrlLajZ$C0sikFQQ3SWaFAZ1Me0Z/1",1,0,0,0,0,1366642540,1,0,,1371033743,0
77 changes: 71 additions & 6 deletions Tests/Functional/Controller/Backend/LocalizationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
use SBUERK\TYPO3\Testing\SiteHandling\SiteBasedTestTrait;
use SBUERK\TYPO3\Testing\TestCase\FunctionalTestCase;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use WebVision\Deepl\Base\Controller\Backend\LocalizationController;
Expand Down Expand Up @@ -52,12 +54,12 @@ public static function dispatchGetLocalizationModesEventReturnsExpectedDefaultMo
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.translate',
'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.translate',
'icon' => 'actions-localize',
'before' => ['copy'],
'before' => ['copyFromLanguage'],
'after' => [],
'restrictedSourceLanguageIds' => null,
],
[
'identifier' => 'copy',
'identifier' => 'copyFromLanguage',
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.copy',
'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.copy',
'icon' => 'actions-edit-copy',
Expand All @@ -79,12 +81,12 @@ public static function dispatchGetLocalizationModesEventReturnsExpectedDefaultMo
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.translate',
'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.translate',
'icon' => 'actions-localize',
'before' => ['copy'],
'before' => ['copyFromLanguage'],
'after' => [],
'restrictedSourceLanguageIds' => null,
],
[
'identifier' => 'copy',
'identifier' => 'copyFromLanguage',
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.copy',
'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.copy',
'icon' => 'actions-edit-copy',
Expand Down Expand Up @@ -114,7 +116,7 @@ public static function dispatchGetLocalizationModesEventReturnsExpectedDefaultMo
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.translate',
'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.translate',
'icon' => 'actions-localize',
'before' => ['copy'],
'before' => ['copyFromLanguage'],
'after' => [],
'restrictedSourceLanguageIds' => null,
],
Expand All @@ -128,7 +130,7 @@ public static function dispatchGetLocalizationModesEventReturnsExpectedDefaultMo
'expectedModesJsonString' => \json_encode(
[
[
'identifier' => 'copy',
'identifier' => 'copyFromLanguage',
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.copy',
'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.copy',
'icon' => 'actions-edit-copy',
Expand Down Expand Up @@ -187,6 +189,69 @@ public function dispatchGetLocalizationModesEventReturnsExpectedDefaultModesBase
$this->assertSame($expectedModesJsonString, \json_encode($modes, JSON_THROW_ON_ERROR));
}

public static function translationModesDataProvider(): \Generator
{
yield 'Translation mode "localize" works' => [
'getParams' => [
'pageId' => 3,
'srcLanguageId' => 0,
'destLanguageId' => 1,
'action' => 'localize',
'uidList' => [1],
],
'expectedFixture' => __DIR__ . '/Fixtures/TranslationModes/Result/localize.csv',
];
yield 'Translation mode "copy" works' => [
'getParams' => [
'pageId' => 3,
'srcLanguageId' => 0,
'destLanguageId' => 1,
'action' => 'copyFromLanguage',
'uidList' => [1],
],
'expectedFixture' => __DIR__ . '/Fixtures/TranslationModes/Result/copyToLanguage.csv',
];
}

/**
* @param array{
* pageId: int,
* srcLanguageId: int,
* destLanguageId: int,
* action: string,
* uidList: int[]
* } $getParams
*/
#[DataProvider('translationModesDataProvider')]
#[Test]
public function translationModesWorkAsExpected(
array $getParams,
string $expectedFixture
): void {
$this->importCSVDataSet(__DIR__ . '/Fixtures/TranslationModes/TranslationModeSetup.csv');
$this->writeSiteConfiguration(
identifier: 'acme',
site: $this->buildSiteConfiguration(
rootPageId: 1,
),
languages: [
$this->buildDefaultLanguageConfiguration('EN', '/'),
$this->buildLanguageConfiguration('EN', '/eb/', ['EN'], 'strict'),
$this->buildLanguageConfiguration('DE', '/de/', ['DE'], 'strict'),
$this->buildLanguageConfiguration('FR', '/fr/', ['FR'], 'strict'),
],
);
$this->setUpFrontendRootPage(1, [], []);
$beUser = $this->setUpBackendUser(1);
$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)
->createFromUserPreferences($beUser);
$request = (new ServerRequest('http://localhost/typo3/ajax/records/localize/process'))
->withQueryParams($getParams);
$response = $this->createSubject()->localizeRecords($request);
$this->assertSame(200, $response->getStatusCode());
$this->assertCSVDataSet($expectedFixture);
}

private function createSubject(): LocalizationController
{
return $this->get(LocalizationController::class);
Expand Down