[BUGFIX] EXT:form: Make hardcoded messages translatable 21/35621/7
authorMichael Oehlhof <typo3@oehlhof.de>
Tue, 23 Dec 2014 02:09:40 +0000 (03:09 +0100)
committerFrank Nägler <typo3@naegler.net>
Sat, 4 Apr 2015 19:25:22 +0000 (21:25 +0200)
After saving a form, we can see the "Changes saved successfully"
or "Failed to save the form" message boxes.

These messages were hardcoded and are now available in the
locallang_wizard.xlf file.

Change-Id: If68d0e8dc7118ebe2fdbf1ff62d2acd785e197e6
Resolves: #61293
Releases: master
Reviewed-on: http://review.typo3.org/35621
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
Reviewed-by: Frank Nägler <typo3@naegler.net>
Tested-by: Frank Nägler <typo3@naegler.net>
typo3/sysext/form/Classes/View/Wizard/AbstractWizardView.php
typo3/sysext/form/Classes/View/Wizard/LoadWizardView.php
typo3/sysext/form/Classes/View/Wizard/SaveWizardView.php
typo3/sysext/form/Classes/View/Wizard/WizardView.php
typo3/sysext/form/Resources/Private/Language/locallang_wizard.xlf

index 1fdc5fc..a7dae1d 100644 (file)
@@ -36,12 +36,22 @@ abstract class AbstractWizardView {
        protected $repository;
 
        /**
+        * Returns an instance of LanguageService
+        *
+        * @return \TYPO3\CMS\Lang\LanguageService
+        */
+       protected function getLanguageService() {
+               return $GLOBALS['LANG'];
+       }
+
+       /**
         * Creates the object and calls the initialize() method.
         *
         * @param ContentRepository $repository
         */
        public function __construct(ContentRepository $repository) {
                $this->setRepository($repository);
+               $this->getLanguageService()->includeLLFile('EXT:form/Resources/Private/Language/locallang_wizard.xlf');
        }
 
        /**
index ca6c626..ef2d2f3 100644 (file)
@@ -34,7 +34,7 @@ class LoadWizardView extends \TYPO3\CMS\Form\View\Wizard\AbstractWizardView {
        }
 
        /**
-        * Construct the reponse header
+        * Construct the response header
         *
         * @param mixed $jsonObject JSON string, FALSE if not succeeded
         * @return void
@@ -42,7 +42,7 @@ class LoadWizardView extends \TYPO3\CMS\Form\View\Wizard\AbstractWizardView {
        protected function headerOutput($jsonObject) {
                if (!$jsonObject) {
                        header('HTTP/1.1 500 Internal Server Error');
-                       $jsonArray = array('message' => 'Failed to save the form');
+                       $jsonArray = array('message' => $this->getLanguageService()->getLL('action_load_message_failed', FALSE));
                } else {
                        $jsonArray = array('configuration' => $jsonObject);
                }
index 93405c2..b37ac67 100644 (file)
@@ -40,7 +40,7 @@ class SaveWizardView extends \TYPO3\CMS\Form\View\Wizard\AbstractWizardView {
        }
 
        /**
-        * Construct the reponse header
+        * Construct the response header
         *
         * @param string $success JSON string
         * @return void
@@ -48,9 +48,9 @@ class SaveWizardView extends \TYPO3\CMS\Form\View\Wizard\AbstractWizardView {
        protected function headerOutput($success) {
                if (!$success) {
                        header('HTTP/1.1 500 Internal Server Error');
-                       $jsonArray = array('message' => 'Failed to save the form');
+                       $jsonArray = array('message' => $this->getLanguageService()->getLL('action_save_message_failed', FALSE));
                } else {
-                       $jsonArray = array('message' => 'Changes saved successfully');
+                       $jsonArray = array('message' => $this->getLanguageService()->getLL('action_save_message_saved', FALSE));
                }
                $json = json_encode($jsonArray);
                header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
index f768902..2b66204 100644 (file)
@@ -41,11 +41,6 @@ class WizardView extends \TYPO3\CMS\Form\View\Wizard\AbstractWizardView {
        protected $pageRenderer;
 
        /**
-        * @var \TYPO3\CMS\Lang\LanguageService;
-        */
-       protected $languageService;
-
-       /**
         * Constructs this view
         *
         * Defines the global variable SOBE. Normally this is used by the wizards
@@ -59,8 +54,6 @@ class WizardView extends \TYPO3\CMS\Form\View\Wizard\AbstractWizardView {
         */
        public function __construct(\TYPO3\CMS\Form\Domain\Repository\ContentRepository $repository) {
                parent::__construct($repository);
-               $this->languageService = $GLOBALS['LANG'];
-               $this->languageService->includeLLFile('EXT:form/Resources/Private/Language/locallang_wizard.xlf');
                $GLOBALS['SOBE'] = $this;
                // Define the document template object
                $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
@@ -101,7 +94,7 @@ class WizardView extends \TYPO3\CMS\Form\View\Wizard\AbstractWizardView {
                // Getting the body content
                $markers['CONTENT'] = $this->getBodyContent();
                // Build the HTML for the module
-               $content = $this->doc->startPage($this->languageService->getLL('title', TRUE));
+               $content = $this->doc->startPage($this->getLanguageService()->getLL('title', TRUE));
                $content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markers);
                $content .= $this->doc->endPage();
                $content = $this->doc->insertStylesAndJS($content);
@@ -271,8 +264,8 @@ class WizardView extends \TYPO3\CMS\Form\View\Wizard\AbstractWizardView {
         * @return void
         */
        protected function loadLocalization() {
-               $wizardLabels = $this->languageService->includeLLFile('EXT:form/Resources/Private/Language/locallang_wizard.xlf', FALSE, TRUE);
-               $controllerLabels = $this->languageService->includeLLFile('EXT:form/Resources/Private/Language/locallang_controller.xlf', FALSE, TRUE);
+               $wizardLabels = $this->getLanguageService()->includeLLFile('EXT:form/Resources/Private/Language/locallang_wizard.xlf', FALSE, TRUE);
+               $controllerLabels = $this->getLanguageService()->includeLLFile('EXT:form/Resources/Private/Language/locallang_controller.xlf', FALSE, TRUE);
                \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($controllerLabels, $wizardLabels);
                $this->pageRenderer->addInlineLanguageLabelArray($controllerLabels['default']);
        }
@@ -335,7 +328,7 @@ class WizardView extends \TYPO3\CMS\Form\View\Wizard\AbstractWizardView {
                // Close
                $getPostVariables = GeneralUtility::_GP('P');
                $buttons['close'] = '<a href="#" onclick="' . htmlspecialchars(('jumpToUrl(unescape(\'' . rawurlencode(GeneralUtility::sanitizeLocalUrl($getPostVariables['returnUrl'])) . '\')); return false;')) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-close', array(
-                       'title' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE)
+                       'title' => $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE)
                )) . '</a>';
                return $buttons;
        }
@@ -353,7 +346,10 @@ class WizardView extends \TYPO3\CMS\Form\View\Wizard\AbstractWizardView {
                        $bodyContent = '';
                } else {
                        /** @var $flashMessage FlashMessage */
-                       $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $this->languageService->getLL('errorMessage', TRUE), $this->languageService->getLL('errorTitle', TRUE), FlashMessage::ERROR);
+                       $flashMessage = GeneralUtility::makeInstance(FlashMessage::class,
+                               $this->getLanguageService()->getLL('errorMessage', TRUE),
+                               $this->getLanguageService()->getLL('errorTitle', TRUE),
+                               FlashMessage::ERROR);
                        $bodyContent = $flashMessage->render();
                }
                return $bodyContent;
index 411be0a..776c7e7 100644 (file)
                        <trans-unit id="action_save_error">
                                <source>Server-side failure with status code</source>
                        </trans-unit>
+                       <trans-unit id="action_save_message_failed">
+                               <source>Failed to save the form</source>
+                       </trans-unit>
+                       <trans-unit id="action_save_message_saved">
+                               <source>Changes saved successfully</source>
+                       </trans-unit>
+                       <trans-unit id="action_load_message_failed">
+                               <source>Failed to save the form</source>
+                       </trans-unit>
                        <trans-unit id="button_remove">
                                <source>Remove</source>
                        </trans-unit>