[FEATURE] Add page.addInlineLanguageLabelFiles 39/29139/12
authorLars Peipmann <lars@peipmann.de>
Fri, 4 Apr 2014 07:26:29 +0000 (09:26 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Fri, 7 Aug 2015 11:01:17 +0000 (13:01 +0200)
This patch adds the possibility to configure PageRenderer
->inlineLanguageLabelFiles with Typoscript.

Resolves: #57632
Releases: master
Change-Id: Iaf4698259836bce2078df711fbdb492b1a61c121
Reviewed-on: http://review.typo3.org/29139
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/core/Documentation/Changelog/master/Feature-57632-AddInlineLanguageLabelFilesWithTypoScript.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/Page/PageGenerator.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-57632-AddInlineLanguageLabelFilesWithTypoScript.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-57632-AddInlineLanguageLabelFilesWithTypoScript.rst
new file mode 100644 (file)
index 0000000..a87e940
--- /dev/null
@@ -0,0 +1,37 @@
+=====================================================================
+Feature: #57632 - Include inline language label files with TypoScript
+=====================================================================
+
+Description
+===========
+
+It is now possible to add inline language label files with TypoScript.
+
+Usage
+-----
+If you want to include inline labels from a XLF file, you have to specify that file in your TypoScript with a custom key in the new
+``inlineLanguageLabelFiles`` section. In addition to the file you can configure three optional parameters:
+
+- ``selectionPrefix``: Only label keys that start with this prefix will be included (default: '')
+- ``stripFromSelectionName``: A string that will be removed from any included label key (default: '')
+- ``errorMode``: Error mode if the file could not be found: 0 - syslog entry, 1 - do nothing, 2 - throw an exception (default: 0)
+
+Example
+-------
+
+.. code-block:: typoscript
+
+       page = PAGE
+       page.inlineLanguageLabelFiles {
+               someLabels = EXT:myExt/Resources/Private/Language/locallang.xlf
+               someLabels.selectionPrefix = idPrefix
+               someLabels.stripFromSelectionName = strip_me
+               someLabels.errorMode = 2
+       }
+
+Output in the HTML head:
+
+.. code-block:: javascript
+
+       var TYPO3 = TYPO3 || {};
+       TYPO3.lang = {"firstLabel":[{"source":"first Label","target":"erstes Label"}],"secondLabel":[{"source":"second Label","target":"zweites Label"}]};
index e1e377b..8a266d0 100644 (file)
@@ -876,6 +876,23 @@ class PageGenerator {
                                $pageRenderer->addJsFooterInlineCode('TS_inlineFooter', $inlineFooterJs, $tsfe->config['config']['compressJs']);
                        }
                }
+               if (is_array($tsfe->pSetup['inlineLanguageLabelFiles.'])) {
+                       foreach ($tsfe->pSetup['inlineLanguageLabelFiles.'] as $key => $languageFile) {
+                               if (is_array($languageFile)) {
+                                       continue;
+                               }
+                               $languageFileConfig = &$tsfe->pSetup['inlineLanguageLabelFiles.'][$key . '.'];
+                               if (isset($languageFileConfig['if.']) && !$tsfe->cObj->checkIf($languageFileConfig['if.'])) {
+                                       continue;
+                               }
+                               $pageRenderer->addInlineLanguageLabelFile(
+                                       $languageFile,
+                                       $languageFileConfig['selectionPrefix'] ?: '',
+                                       $languageFileConfig['stripFromSelectionName'] ?: '',
+                                       $languageFileConfig['errorMode'] ? (int)$languageFileConfig['errorMode'] : 0
+                               );
+                       }
+               }
                // ExtJS specific code
                if (is_array($tsfe->pSetup['inlineLanguageLabel.'])) {
                        $pageRenderer->addInlineLanguageLabelArray($tsfe->pSetup['inlineLanguageLabel.'], TRUE);