[BUGFIX] Translation of extbase-core
authortomas <t.grzemski@macopedia.pl>
Mon, 1 Apr 2013 19:54:48 +0000 (21:54 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 27 Apr 2013 11:54:12 +0000 (13:54 +0200)
Made massages from validators and property errors translatable.

Change-Id: I376f55a22d9e7d822146f0f935b1de24098b37cf
Fixes: #6538
Releases: 6.0, 6.1
Reviewed-on: https://review.typo3.org/20218
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
17 files changed:
typo3/sysext/extbase/Classes/Validation/Validator/AlphanumericValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/DateTimeValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/EmailAddressValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/FloatValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/GenericObjectValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/IntegerValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/NotEmptyValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/NumberRangeValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/NumberValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/RegularExpressionValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/StringLengthValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/StringValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/TextValidator.php
typo3/sysext/extbase/Resources/Private/Language/locallang.xlf [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/FloatValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/IntegerValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/NumberRangeValidatorTest.php

index babac7b..c6e5a05 100644 (file)
@@ -44,7 +44,11 @@ class AlphanumericValidator extends \TYPO3\CMS\Extbase\Validation\Validator\Abst
        public function isValid($value) {
                $this->errors = array();
                if (!is_string($value) || preg_match('/^[\pL\d]*$/u', $value) !== 1) {
-                       $this->addError('The given subject was not a valid alphanumeric string.', 1221551320);
+                       $this->addError(
+                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       'validator.alphanumeric.notvalid',
+                                       'extbase'
+                               ), 1221551320);
                        return FALSE;
                }
 
index cd27c81..4f2ff41 100644 (file)
@@ -45,7 +45,14 @@ class DateTimeValidator extends \TYPO3\CMS\Extbase\Validation\Validator\Abstract
                if ($value instanceof \DateTime) {
                        return TRUE;
                }
-               $this->addError('The given subject was not a valid DateTime. Got: "%1$d"', 1238087674, array(gettype($value)));
+               $this->addError(
+                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               'validator.datetime.notvalid',
+                               'extbase',
+                               array(
+                                       gettype($value)
+                               )
+                       ), 1238087674, array(gettype($value)));
                return FALSE;
        }
 }
index 7abb84b..a8a63d2 100644 (file)
@@ -44,7 +44,11 @@ class EmailAddressValidator extends \TYPO3\CMS\Extbase\Validation\Validator\Abst
                if (is_string($value) && \TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($value)) {
                        return TRUE;
                }
-               $this->addError('The given subject was not a valid email address.', 1221559976);
+               $this->addError(
+                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               'validator.emailaddress.notvalid',
+                               'extbase'
+                       ), 1221559976);
                return FALSE;
        }
 }
index a19ccbe..d45eeab 100644 (file)
@@ -45,7 +45,11 @@ class FloatValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractVal
                if (is_float($value) || is_string($value) && strpos($value, '.') !== FALSE && preg_match('/^[0-9.e+-]+$/', $value)) {
                        return TRUE;
                }
-               $this->addError('The given subject was not a valid float.', 1221560288);
+               $this->addError(
+                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                       'validator.float.notvalid',
+                       'extbase'
+                       ), 1221560288);
                return FALSE;
        }
 }
index 30bd30c..d019982 100644 (file)
@@ -122,7 +122,11 @@ class GenericObjectValidator extends \TYPO3\CMS\Extbase\Validation\Validator\Abs
         */
        public function isValid($value) {
                if (!is_object($value)) {
-                       $this->addError('Value is no object.', 1241099148);
+                       $this->addError(
+                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       'validator.genericobject.noobject',
+                                       'extbase'
+                               ), 1241099148);
                        return FALSE;
                }
                $result = TRUE;
index dbad5a8..0ca9cc0 100644 (file)
@@ -45,7 +45,11 @@ class IntegerValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractV
                if (filter_var($value, FILTER_VALIDATE_INT) !== FALSE) {
                        return TRUE;
                }
-               $this->addError('The given subject was not a valid integer.', 1221560494);
+               $this->addError(
+                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                       'validator.integer.notvalid',
+                       'extbase'
+                       ), 1221560494);
                return FALSE;
        }
 }
index aaf1003..e98473c 100644 (file)
@@ -43,23 +43,39 @@ class NotEmptyValidator extends \TYPO3\CMS\Extbase\Validation\Validator\Abstract
        public function isValid($value) {
                $this->errors = array();
                if ($value === NULL) {
-                       $this->addError('The given subject was NULL.', 1221560910);
+                       $this->addError(
+                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       'validator.notempty.null',
+                                       'extbase'
+                               ), 1221560910);
                        return FALSE;
                }
                if ($value === '') {
-                       $this->addError('The given subject was empty.', 1221560718);
+                       $this->addError(
+                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       'validator.notempty.empty',
+                                       'extbase'
+                               ), 1221560718);
                        return FALSE;
                }
                if (is_array($value) && empty($value)) {
-                       $this->addError('The given subject was empty.', 1347992400);
+                       $this->addError(
+                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       'validator.notempty.empty',
+                                       'extbase'
+                               ), 1347992400);
                        return FALSE;
                }
                if (is_object($value) && $value instanceof \Countable && $value->count() === 0) {
-                       $this->addError('The given subject was empty.', 1347992453);
+                       $this->addError(
+                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       'validator.notempty.empty',
+                                       'extbase'
+                               ), 1347992453);
                        return FALSE;
                }
                return TRUE;
        }
 }
 
-?>
\ No newline at end of file
+?>
index a2afe1b..6a2dcad 100644 (file)
@@ -49,7 +49,11 @@ class NumberRangeValidator extends \TYPO3\CMS\Extbase\Validation\Validator\Abstr
                }
                $this->errors = array();
                if (!is_numeric($value)) {
-                       $this->addError('The given subject was not a valid number.', 1221563685);
+                       $this->addError(
+                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       'validator.numberrange.notvalid',
+                                       'extbase'
+                               ), 1221563685);
                        return FALSE;
                }
                $startRange = isset($this->options['startRange']) ? intval($this->options['startRange']) : 0;
@@ -62,7 +66,15 @@ class NumberRangeValidator extends \TYPO3\CMS\Extbase\Validation\Validator\Abstr
                if ($value >= $startRange && $value <= $endRange) {
                        return TRUE;
                }
-               $this->addError('The given subject was not in the valid range (%1$d - %2$d).', 1221561046, array($startRange, $endRange));
+               $this->addError(
+                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               'validator.numberrange.range',
+                               'extbase',
+                               array(
+                                       $startRange,
+                                       $endRange
+                               )
+                       ), 1221561046, array($startRange, $endRange));
                return FALSE;
        }
 }
index 09593d5..bb00102 100644 (file)
@@ -45,7 +45,11 @@ class NumberValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractVa
                if (is_numeric($value)) {
                        return TRUE;
                }
-               $this->addError('The given subject was not a valid number.', 1221563685);
+               $this->addError(
+                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               'validator.number.notvalid',
+                               'extbase'
+                       ), 1221563685);
                return FALSE;
        }
 }
index c253312..cd20880 100644 (file)
@@ -45,16 +45,31 @@ class RegularExpressionValidator extends \TYPO3\CMS\Extbase\Validation\Validator
        public function isValid($value) {
                $this->errors = array();
                if (!isset($this->options['regularExpression'])) {
-                       $this->addError('The regular expression was empty.', 1221565132);
+                       $this->addError(
+                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       'validator.regularexpression.empty',
+                                       'extbase'
+                               ), 1221565132);
                        return FALSE;
                }
                $result = preg_match($this->options['regularExpression'], $value);
                if ($result === 0) {
-                       $this->addError('The given subject did not match the pattern.', 1221565130);
+                       $this->addError(
+                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       'validator.regularexpression.nomatch',
+                                       'extbase'
+                               ), 1221565130);
                        return FALSE;
                }
                if ($result === FALSE) {
-                       $this->addError('The regular expression "%1$d" contained an error.', 1221565131, array($this->options['regularExpression']));
+                       $this->addError(
+                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       'validator.regularexpression.error',
+                                       'extbase',
+                                       array(
+                                               $this->options['regularExpression']
+                                       )
+                               ), 1221565131, array($this->options['regularExpression']));
                        return FALSE;
                }
                return TRUE;
index 146ab56..f1b8c15 100644 (file)
@@ -63,11 +63,33 @@ class StringLengthValidator extends \TYPO3\CMS\Extbase\Validation\Validator\Abst
                }
                if ($isValid === FALSE) {
                        if (isset($this->options['minimum']) && isset($this->options['maximum'])) {
-                               $this->addError('The length of the given string was not between %1$d and %2$d characters.', 1238108067, array($this->options['minimum'], $this->options['maximum']));
+                               $this->addError(
+                                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                               'validator.stringlength.between',
+                                               'extbase',
+                                               array (
+                                                       $this->options['minimum'],
+                                                       $this->options['maximum']
+                                               )
+                                       ), 1238108067, array($this->options['minimum'], $this->options['maximum']));
                        } elseif (isset($this->options['minimum'])) {
-                               $this->addError('The length of the given string less than %1$d characters.', 1238108068, array($this->options['minimum']));
+                               $this->addError(
+                                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                               'validator.stringlength.less',
+                                               'extbase',
+                                               array(
+                                                       $this->options['minimum']
+                                               )
+                                       ), 1238108068, array($this->options['minimum']));
                        } else {
-                               $this->addError('The length of the given string exceeded %1$d characters.', 1238108069, array($this->options['maximum']));
+                               $this->addError(
+                                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                               'validator.stringlength.exceed',
+                                               'extbase',
+                                               array(
+                                                       $this->options['maximum']
+                                               )
+                                       ), 1238108069, array($this->options['maximum']));
                        }
                }
                return $isValid;
index 5ee0db3..b0e81cb 100644 (file)
@@ -44,7 +44,11 @@ class StringValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractVa
         */
        public function isValid($value) {
                if (!is_string($value)) {
-                       $this->addError('A valid string is expected.', 1238108067);
+                       $this->addError(
+                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       'validator.string.notvalid',
+                                       'extbase'
+                               ), 1238108067);
                        return FALSE;
                }
                return TRUE;
index 6e2094c..9a11637 100644 (file)
@@ -43,7 +43,11 @@ class TextValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractVali
        public function isValid($value) {
                $this->errors = array();
                if ($value !== filter_var($value, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)) {
-                       $this->addError('The given subject was not a valid text (e.g. contained XML tags).', 1221565786);
+                       $this->addError(
+                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       'validator.text.notvalid',
+                                       'extbase'
+                               ), 1221565786);
                        return FALSE;
                }
                return TRUE;
diff --git a/typo3/sysext/extbase/Resources/Private/Language/locallang.xlf b/typo3/sysext/extbase/Resources/Private/Language/locallang.xlf
new file mode 100644 (file)
index 0000000..9b3b19e
--- /dev/null
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.0">
+       <file source-language="en" datatype="plaintext" original="messages" date="2012-10-17T19:30:32Z" product-name="extbase">
+               <header/>
+               <body>
+                       <trans-unit id="property.error" xml:space="preserve">
+                               <source>Validation errors for property "%s"</source>
+                       </trans-unit>
+                       <trans-unit id="validator.emailaddress.notvalid" xml:space="preserve">
+                               <source>The given subject was not a valid email address.</source>
+                       </trans-unit>
+                       <trans-unit id="validator.stringlength.between" xml:space="preserve">
+                               <source>The length of the given string was not between %s and %s characters.</source>
+                       </trans-unit>
+                       <trans-unit id="validator.stringlength.less" xml:space="preserve">
+                               <source>The length of the given string is less than %s characters.</source>
+                       </trans-unit>
+                       <trans-unit id="validator.string.notvalid" xml:space="preserve">
+                               <source>A valid string is expected.</source>
+                       </trans-unit>
+                       <trans-unit id="validator.stringlength.exceed" xml:space="preserve">
+                               <source>The length of the given string exceeded %s characters.</source>
+                       </trans-unit>
+                       <trans-unit id="validator.alphanumeric.notvalid" xml:space="preserve">
+                               <source>The given subject was not a valid alphanumeric string.</source>
+                       </trans-unit>
+                       <trans-unit id="validator.datetime.notvalid" xml:space="preserve">
+                               <source>The given subject was not a valid DateTime. Got: '%s'</source>
+                       </trans-unit>
+                       <trans-unit id="validator.genericobject.noobject" xml:space="preserve">
+                               <source>Value is no object.</source>
+                       </trans-unit>
+                       <trans-unit id="validator.float.notvalid" xml:space="preserve">
+                               <source>The given subject was not a valid float.</source>
+                       </trans-unit>
+                       <trans-unit id="validator.text.notvalid" xml:space="preserve">
+                               <source>The given subject was not a valid text (e.g. contained XML tags).</source>
+                       </trans-unit>
+                       <trans-unit id="validator.regularexpression.empty" xml:space="preserve">
+                               <source>The regular expression was empty.</source>
+                       </trans-unit>
+                       <trans-unit id="validator.regularexpression.nomatch" xml:space="preserve">
+                               <source>The given subject did not match the pattern.</source>
+                       </trans-unit>
+                       <trans-unit id="validator.regularexpression.error" xml:space="preserve">
+                               <source>The reguar expression '%s' contained an error.</source>
+                       </trans-unit>
+                       <trans-unit id="validator.numberrange.notvalid" xml:space="preserve">
+                               <source>The given subject was not a valid number.</source>
+                       </trans-unit>
+                       <trans-unit id="validator.numberrange.range" xml:space="preserve">
+                               <source>The given subject was not in the valid range (%s - %s).</source>
+                       </trans-unit>
+                       <trans-unit id="validator.notempty.null" xml:space="preserve">
+                               <source>The given subject was NULL.</source>
+                       </trans-unit>
+                       <trans-unit id="validator.notempty.empty" xml:space="preserve">
+                               <source>The given subject was empty.</source>
+                       </trans-unit>
+                       <trans-unit id="validator.number.notvalid" xml:space="preserve">
+                               <source>The given subject was not a valid number.</source>
+                       </trans-unit>
+                       <trans-unit id="validator.integer.notvalid" xml:space="preserve">
+                               <source>The given subject was not a valid integer</source>
+                       </trans-unit>
+               </body>
+       </file>
+</xliff>
\ No newline at end of file
index 036a6a6..7d2cd65 100644 (file)
@@ -91,9 +91,11 @@ class FloatValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @test
         */
        public function floatValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
-               $floatValidator = new \TYPO3\CMS\Extbase\Validation\Validator\FloatValidator();
                $floatValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\FloatValidator', array('addError'), array(), '', FALSE);
-               $floatValidator->expects($this->once())->method('addError')->with('The given subject was not a valid float.', 1221560288);
+
+               $translatedMessage = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('validator.float.notvalid', 'extbase');
+
+               $floatValidator->expects($this->once())->method('addError')->with($translatedMessage, 1221560288);
                $floatValidator->isValid(123456);
        }
 }
index 3cd7e21..8529676 100644 (file)
@@ -90,7 +90,9 @@ class IntegerValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         */
        public function integerValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
                $integerValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\IntegerValidator', array('addError'), array(), '', FALSE);
-               $integerValidator->expects($this->once())->method('addError')->with('The given subject was not a valid integer.', 1221560494);
+
+               $translatedMessage = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('validator.integer.notvalid', 'extbase');
+               $integerValidator->expects($this->once())->method('addError')->with($translatedMessage, 1221560494);
                $integerValidator->isValid('not a number');
        }
 }
index 276a7b8..6857a14 100644 (file)
@@ -75,9 +75,13 @@ class NumberRangeValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCas
         * @test
         */
        public function numberRangeValidatorCreatesTheCorrectErrorForANumberOutOfRange() {
+               $startRange = 1;
+               $endRange = 42;
+               $translatedMessage = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('validator.numberrange.range', 'extbase', array($startRange, $endRange));
+
                $numberRangeValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberRangeValidator', array('addError'), array(), '', FALSE);
-               $numberRangeValidator->expects($this->once())->method('addError')->with('The given subject was not in the valid range (%1$d - %2$d).', 1221561046, array(1, 42));
-               $numberRangeValidator->setOptions(array('startRange' => 1, 'endRange' => 42));
+               $numberRangeValidator->expects($this->once())->method('addError')->with($translatedMessage, 1221561046, array(1, 42));
+               $numberRangeValidator->setOptions(array('startRange' => $startRange, 'endRange' => $endRange));
                $numberRangeValidator->isValid(4711);
        }