[BUGFIX] Allow settings language labels via TS even if no xlf present 73/58373/2
authorMarkus Klein <markus.klein@typo3.org>
Fri, 21 Sep 2018 21:00:34 +0000 (23:00 +0200)
committerBenni Mack <benni@typo3.org>
Mon, 24 Sep 2018 04:12:20 +0000 (06:12 +0200)
Re-establish the functionality to set language labels in TypoScript
even though no locallang.xlf file is present for the given extension.

Resolves: #86194
Releases: master
Change-Id: Ifcd31909fa594be892f93c1037941313011b74cf
Reviewed-on: https://review.typo3.org/58373
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Josef Glatz <josef.glatz@typo3.org>
Tested-by: Josef Glatz <josef.glatz@typo3.org>
Reviewed-by: Georg Tiefenbrunn <georg.tiefenbrunn@gmail.com>
Tested-by: Georg Tiefenbrunn <georg.tiefenbrunn@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/extbase/Classes/Utility/LocalizationUtility.php
typo3/sysext/extbase/Tests/Unit/Utility/LocalizationUtilityTest.php

index 91e583a..6c9e60b 100644 (file)
@@ -240,7 +240,7 @@ class LocalizationUtility
         }
         self::$LOCAL_LANG_UNSET[$languageFilePath] = [];
         foreach ($frameworkConfiguration['_LOCAL_LANG'] as $languageKey => $labels) {
-            if (!(is_array($labels) && isset(self::$LOCAL_LANG[$languageFilePath][$languageKey]))) {
+            if (!is_array($labels)) {
                 continue;
             }
             foreach ($labels as $labelKey => $labelValue) {
index 48d5e5f..3e17481 100644 (file)
@@ -509,4 +509,36 @@ class LocalizationUtilityTest extends UnitTestCase
         $this->expectExceptionCode(1498144052);
         LocalizationUtility::translate('foo/bar', '');
     }
+
+    /**
+     * @test
+     */
+    public function translateWillReturnLabelsFromTsEvenIfNoXlfFileExists()
+    {
+        $reflectionClass = new \ReflectionClass(LocalizationUtility::class);
+
+        $typoScriptLocalLang = [
+            '_LOCAL_LANG' => [
+                'dk' => [
+                    'key1' => 'I am a new key and there is no xlf file',
+                ]
+            ]
+        ];
+
+        $configurationType = ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK;
+        $this->configurationManagerInterfaceProphecy
+            ->getConfiguration($configurationType, 'core', null)
+            ->shouldBeCalled()
+            ->willReturn($typoScriptLocalLang);
+
+        $method = $reflectionClass->getMethod('loadTypoScriptLabels');
+        $method->setAccessible(true);
+        $method->invoke(null, 'core', ''); // setting the language file path to an empty string here
+
+        $GLOBALS['LANG'] = $this->LOCAL_LANG;
+
+        $result = LocalizationUtility::translate('key1', 'core', null, 'dk');
+        $this->assertNotNull($result);
+        $this->assertEquals('I am a new key and there is no xlf file', $result);
+    }
 }