Skip to content

Commit

Permalink
[!!!][TASK] Remove language related JavaScript files
Browse files Browse the repository at this point in the history
The "language" extension has two JavaScript files left:

- Typo3Lang.js, was required for ExtJS, which has been removed
some time ago.
- Lang.js, is a RequireJS module that mimics the behavior of Typo3Lang.

As the desired functionality may be achieved with plain PHP, the module
is rendered obsolete and gets removed.

Resolves: #84148
Releases: master
Change-Id: Ice3df96195bb435da8df1004d1e9304ec7601d26
Reviewed-on: https://review.typo3.org/56023
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
  • Loading branch information
andreaskienast authored and bmack committed Mar 7, 2018
1 parent e10bee1 commit 64f8e8d
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 131 deletions.
4 changes: 0 additions & 4 deletions Build/tsconfig.json
Expand Up @@ -50,10 +50,6 @@
"../typo3/sysext/install/Resources/Public/JavaScript/*",
"../typo3/sysext/install/Resources/Private/TypeScript/*"
],
"TYPO3/CMS/Lang/*": [
"../typo3/sysext/lang/Resources/Public/JavaScript/*",
"../typo3/sysext/lang/Resources/Private/TypeScript/*"
],
"TYPO3/CMS/Linkvalidator/*": [
"../typo3/sysext/linkvalidator/Resources/Public/JavaScript/*",
"../typo3/sysext/linkvalidator/Resources/Private/TypeScript/*"
Expand Down
Expand Up @@ -19,8 +19,7 @@ define(['jquery',
'd3',
'TYPO3/CMS/Backend/PageTree/PageTreeDragDrop',
'TYPO3/CMS/Backend/Tooltip',
'TYPO3/CMS/Backend/SvgTree',
'TYPO3/CMS/Lang/Lang'
'TYPO3/CMS/Backend/SvgTree'
],
function($, Icons, d3, PageTreeDragDrop) {
'use strict';
Expand Down
3 changes: 1 addition & 2 deletions typo3/sysext/backend/Resources/Public/JavaScript/SvgTree.js
Expand Up @@ -22,8 +22,7 @@ define(
'TYPO3/CMS/Backend/Modal',
'TYPO3/CMS/Backend/Severity',
'TYPO3/CMS/Backend/Notification',
'TYPO3/CMS/Backend/Icons',
'TYPO3/CMS/Lang/Lang'
'TYPO3/CMS/Backend/Icons'
],
function($, d3, ContextMenu, Modal, Severity, Notification, Icons) {
'use strict';
Expand Down
34 changes: 29 additions & 5 deletions typo3/sysext/core/Classes/Page/PageRenderer.php
Expand Up @@ -1887,22 +1887,46 @@ protected function renderMainJavaScriptLibraries()
if (TYPO3_MODE === 'BE') {
$this->addAjaxUrlsToInlineSettings();
}
$inlineSettings = $this->inlineLanguageLabels ? 'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels) . ';' : '';
$inlineSettings = '';
$languageLabels = $this->parseLanguageLabelsForJavaScript();
if (!empty($languageLabels)) {
$inlineSettings .= 'TYPO3.lang = ' . json_encode($languageLabels) . ';';
}
$inlineSettings .= $this->inlineSettings ? 'TYPO3.settings = ' . json_encode($this->inlineSettings) . ';' : '';

if ($inlineSettings !== '') {
// make sure the global TYPO3 is available
$inlineSettings = 'var TYPO3 = TYPO3 || {};' . CRLF . $inlineSettings;
$out .= $this->inlineJavascriptWrap[0] . $inlineSettings . $this->inlineJavascriptWrap[1];
// Add language module only if also jquery is guaranteed to be there
if (TYPO3_MODE === 'BE' && !empty($this->jQueryVersions)) {
$this->loadRequireJsModule('TYPO3/CMS/Lang/Lang');
}
}

return $out;
}

/**
* Converts the language labels for usage in JavaScript
*
* @return array
*/
protected function parseLanguageLabelsForJavaScript(): array
{
if (empty($this->inlineLanguageLabels)) {
return [];
}

$labels = [];
foreach ($this->inlineLanguageLabels as $key => $translationUnit) {
if (is_array($translationUnit)) {
$translationUnit = current($translationUnit);
$labels[$key] = $translationUnit['target'] ?? $translationUnit['source'];
} else {
$labels[$key] = $translationUnit;
}
}

return $labels;
}

/**
* Load the language strings into JavaScript
*/
Expand Down
@@ -0,0 +1,33 @@
.. include:: ../../Includes.txt

=================================================================
Breaking: #84148 - RequireJS module for language handling removed
=================================================================

See :issue:`84148`

Description
===========

Since the removal of ExtJS, the JavaScript files that handle the localization of labels in backend modules became obsolete and are removed.


Impact
======

Depending on the RequireJS module :js:`TYPO3/CMS/Lang/Lang` will result in `404` errors, as the module has been removed.


Affected Installations
======================

Every 3rd party extension depending on :js:`TYPO3/CMS/Lang/Lang` is affected.


Migration
=========

Remove the module from the affected RequireJS modules. The labels are now prepared by the PageRenderer and passed
to :js:`TYPO3.lang` without the need of additional JavaScript.

.. index:: Backend, JavaScript, NotScanned
44 changes: 44 additions & 0 deletions typo3/sysext/core/Tests/Unit/Page/PageRendererTest.php
Expand Up @@ -311,4 +311,48 @@ public function unsetAddedMetaTag()
$expectedResult = [];
$this->assertSame($expectedResult, $actualResult);
}

/**
* @test
*/
public function parseLanguageLabelsForJavaScriptReturnsEmptyStringIfEmpty()
{
$subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
$inlineLanguageLabels = [];
$subject->_set('inlineLanguageLabels', $inlineLanguageLabels);
$actual = $subject->_call('parseLanguageLabelsForJavaScript');
$this->assertEmpty($actual);
}

/**
* @test
*/
public function parseLanguageLabelsForJavaScriptReturnsFlatArray()
{
$subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
$inlineLanguageLabels = [
'key' => 'label',
'foo' => 'bar',
'husel' => [
[
'source' => 'pusel',
]
],
'hello' => [
[
'source' => 'world',
'target' => 'welt',
]
],
];
$subject->_set('inlineLanguageLabels', $inlineLanguageLabels);
$expected = [
'key' => 'label',
'foo' => 'bar',
'husel' => 'pusel',
'hello' => 'welt',
];
$actual = $subject->_call('parseLanguageLabelsForJavaScript');
$this->assertSame($expected, $actual);
}
}
47 changes: 0 additions & 47 deletions typo3/sysext/lang/Resources/Public/JavaScript/Lang.js

This file was deleted.

71 changes: 0 additions & 71 deletions typo3/sysext/lang/Resources/Public/JavaScript/Typo3Lang.js

This file was deleted.

0 comments on commit 64f8e8d

Please sign in to comment.