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

[TASK] Use alternative language paths for locallang #1617

Merged
merged 1 commit into from
Nov 20, 2020
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
2 changes: 2 additions & 0 deletions config/v9/typo3-93.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Ssch\TYPO3Rector\Rector\v9\v3\BackendUserAuthenticationSimplelogRector;
use Ssch\TYPO3Rector\Rector\v9\v3\BackendUtilityGetModuleUrlRector;
use Ssch\TYPO3Rector\Rector\v9\v3\CopyMethodGetPidForModTSconfigRector;
use Ssch\TYPO3Rector\Rector\v9\v3\MoveLanguageFilesFromExtensionLangRector;
use Ssch\TYPO3Rector\Rector\v9\v3\PropertyUserTsToMethodGetTsConfigOfBackendUserAuthenticationRector;
use Ssch\TYPO3Rector\Rector\v9\v3\RemoveColPosParameterRector;
use Ssch\TYPO3Rector\Rector\v9\v3\UseMethodGetPageShortcutDirectlyFromSysPageRector;
Expand Down Expand Up @@ -40,4 +41,5 @@
$services->set(UseMethodGetPageShortcutDirectlyFromSysPageRector::class);
$services->set(CopyMethodGetPidForModTSconfigRector::class);
$services->set(BackendUserAuthenticationSimplelogRector::class);
$services->set(MoveLanguageFilesFromExtensionLangRector::class);
};
78 changes: 78 additions & 0 deletions src/Rector/v9/v3/MoveLanguageFilesFromExtensionLangRector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

namespace Ssch\TYPO3Rector\Rector\v9\v3;

use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Scalar\String_;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\RectorDefinition\CodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;

/**
* @see https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/9.3/Deprecation-84680-MoveLastLanguageFilesAwayFromExtlangAndRemoveExtlangCompletely.html
*/
final class MoveLanguageFilesFromExtensionLangRector extends AbstractRector
{
/**
* @var string[]
*/
private const MAPPING_OLD_TO_NEW_PATHS = [
'lang/Resources/Private/Language/locallang_alt_intro.xlf' => 'about/Resources/Private/Language/Modules/locallang_alt_intro.xlf',
'lang/Resources/Private/Language/locallang_alt_doc.xlf' => 'backend/Resources/Private/Language/locallang_alt_doc.xlf',
'lang/Resources/Private/Language/locallang_login.xlf' => 'backend/Resources/Private/Language/locallang_login.xlf',
'lang/Resources/Private/Language/locallang_common.xlf' => 'core/Resources/Private/Language/locallang_common.xlf',
'lang/Resources/Private/Language/locallang_core.xlf' => 'core/Resources/Private/Language/locallang_core.xlf',
'lang/Resources/Private/Language/locallang_general.xlf' => 'core/Resources/Private/Language/locallang_general.xlf',
'lang/Resources/Private/Language/locallang_misc.xlf' => 'core/Resources/Private/Language/locallang_misc.xlf',
'lang/Resources/Private/Language/locallang_mod_web_list.xlf' => 'core/Resources/Private/Language/locallang_mod_web_list.xlf',
'lang/Resources/Private/Language/locallang_tca.xlf' => 'core/Resources/Private/Language/locallang_tca.xlf',
'lang/Resources/Private/Language/locallang_tsfe.xlf' => 'core/Resources/Private/Language/locallang_tsfe.xlf',
'lang/Resources/Private/Language/locallang_wizards.xlf' => 'core/Resources/Private/Language/locallang_wizards.xlf',
'lang/Resources/Private/Language/locallang_browse_links.xlf' => 'recordlist/Resources/Private/Language/locallang_browse_links.xlf',
'lang/Resources/Private/Language/locallang_tcemain.xlf' => 'workspaces/Resources/Private/Language/locallang_tcemain.xlf',
];

public function getNodeTypes(): array
{
return [String_::class];
}

/**
* @param String_ $node
*/
public function refactor(Node $node): ?Node
{
$value = $this->getValue($node);

foreach (self::MAPPING_OLD_TO_NEW_PATHS as $oldPath => $newPath) {
if (Strings::contains($value, $oldPath)) {
return new String_(str_replace($oldPath, $newPath, $value));
}
}

return null;
}

/**
* @codeCoverageIgnore
*/
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('', [
new CodeSample(<<<'PHP'
use TYPO3\CMS\Core\Localization\LanguageService;
$languageService = new LanguageService();
$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.no_title');
PHP
, <<<'PHP'
use TYPO3\CMS\Core\Localization\LanguageService;
$languageService = new LanguageService();
$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.no_title');
PHP
),
]);
}
}
3 changes: 3 additions & 0 deletions stubs/Core/Localization/LanguageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ final class LanguageService
{
public function init(string $language): void
{
}

public function sL($label): void
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
<?php

namespace Ssch\TYPO3Rector\Tests\Rector\v9\v3\MoveLanguageFilesFromExtensionLang\Fixture;
use TYPO3\CMS\Core\Localization\LanguageService;

/** Keep it in the comments LLL:EXT:lang/Resources/Private/Language/locallang_alt_intro.xlf */

class MySpecialClass
{
protected $itemsConfiguration = [
'edit' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.edit',
'iconIdentifier' => 'actions-page-open',
'callbackAction' => 'editFile'
],
'rename' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.rename',
'iconIdentifier' => 'actions-edit-rename',
'callbackAction' => 'renameFile'
],
'upload' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.upload',
'iconIdentifier' => 'actions-edit-upload',
'callbackAction' => 'uploadFile'
],
'new' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.new',
'iconIdentifier' => 'actions-document-new',
'callbackAction' => 'createFile'
],
'info' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.info',
'iconIdentifier' => 'actions-document-info',
'callbackAction' => 'openInfoPopUp'
],
'divider' => [
'type' => 'divider'
],
'copy' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.copy',
'iconIdentifier' => 'actions-edit-copy',
'callbackAction' => 'copyFile'
],
'copyRelease' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.copy',
'iconIdentifier' => 'actions-edit-copy-release',
'callbackAction' => 'copyReleaseFile'
],
'cut' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.cut',
'iconIdentifier' => 'actions-edit-cut',
'callbackAction' => 'cutFile'
],
'cutRelease' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.cutrelease',
'iconIdentifier' => 'actions-edit-cut-release',
'callbackAction' => 'cutReleaseFile'
],
'pasteInto' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.pasteinto',
'iconIdentifier' => 'actions-document-paste-into',
'callbackAction' => 'pasteFileInto'
],
'divider2' => [
'type' => 'divider'
],
'delete' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.delete',
'iconIdentifier' => 'actions-edit-delete',
'callbackAction' => 'deleteFile'
],
];

/**
* @var string
*/
private $labels = 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:';

protected function getLabel($key)
{
return sprintf($this->labels . $key);
}
}

$languageService = new LanguageService();
$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_alt_intro.xlf');
$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_alt_doc.xlf');
$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_login.xlf');
$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf');
$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf');
$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf');
$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf');
$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf');
$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf');
$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_tsfe.xlf');
$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf');
$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_browse_links.xlf');
$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_tcemain.xlf');

$coreLabels = 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:';
$languageService->sL($coreLabels.'labels.reload');

?>
-----
<?php

namespace Ssch\TYPO3Rector\Tests\Rector\v9\v3\MoveLanguageFilesFromExtensionLang\Fixture;
use TYPO3\CMS\Core\Localization\LanguageService;

/** Keep it in the comments LLL:EXT:lang/Resources/Private/Language/locallang_alt_intro.xlf */

class MySpecialClass
{
protected $itemsConfiguration = [
'edit' => [
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.edit',
'iconIdentifier' => 'actions-page-open',
'callbackAction' => 'editFile'
],
'rename' => [
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.rename',
'iconIdentifier' => 'actions-edit-rename',
'callbackAction' => 'renameFile'
],
'upload' => [
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.upload',
'iconIdentifier' => 'actions-edit-upload',
'callbackAction' => 'uploadFile'
],
'new' => [
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.new',
'iconIdentifier' => 'actions-document-new',
'callbackAction' => 'createFile'
],
'info' => [
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.info',
'iconIdentifier' => 'actions-document-info',
'callbackAction' => 'openInfoPopUp'
],
'divider' => [
'type' => 'divider'
],
'copy' => [
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.copy',
'iconIdentifier' => 'actions-edit-copy',
'callbackAction' => 'copyFile'
],
'copyRelease' => [
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.copy',
'iconIdentifier' => 'actions-edit-copy-release',
'callbackAction' => 'copyReleaseFile'
],
'cut' => [
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.cut',
'iconIdentifier' => 'actions-edit-cut',
'callbackAction' => 'cutFile'
],
'cutRelease' => [
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.cutrelease',
'iconIdentifier' => 'actions-edit-cut-release',
'callbackAction' => 'cutReleaseFile'
],
'pasteInto' => [
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.pasteinto',
'iconIdentifier' => 'actions-document-paste-into',
'callbackAction' => 'pasteFileInto'
],
'divider2' => [
'type' => 'divider'
],
'delete' => [
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.delete',
'iconIdentifier' => 'actions-edit-delete',
'callbackAction' => 'deleteFile'
],
];

/**
* @var string
*/
private $labels = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:';

protected function getLabel($key)
{
return sprintf($this->labels . $key);
}
}

$languageService = new LanguageService();
$languageService->sL('LLL:EXT:about/Resources/Private/Language/Modules/locallang_alt_intro.xlf');
$languageService->sL('LLL:EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf');
$languageService->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf');
$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf');
$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf');
$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf');
$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf');
$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf');
$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf');
$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_tsfe.xlf');
$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf');
$languageService->sL('LLL:EXT:recordlist/Resources/Private/Language/locallang_browse_links.xlf');
$languageService->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang_tcemain.xlf');

$coreLabels = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:';
$languageService->sL($coreLabels.'labels.reload');

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Ssch\TYPO3Rector\Tests\Rector\v9\v3\MoveLanguageFilesFromExtensionLang;

use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Ssch\TYPO3Rector\Rector\v9\v3\MoveLanguageFilesFromExtensionLangRector;
use Symplify\SmartFileSystem\SmartFileInfo;

final class MoveLanguageFilesFromExtensionLangRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideDataForTest()
*/
public function test(SmartFileInfo $file): void
{
$this->doTestFileInfo($file);
}

public function provideDataForTest(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

protected function getRectorClass(): string
{
return MoveLanguageFilesFromExtensionLangRector::class;
}
}