Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[Minor BC] Remove translation of validator keys #5664

Merged
merged 1 commit into from

3 participants

@macnibblet

Removes the translation of validator message keys which is totally
absurd in the first place. They are constants that should not be
modified.

@macnibblet macnibblet [Minor BC] Remove translation of validator keys
Removes the translation of validator message ***keys*** which is totally
absurd in the first place. They are constants that should not be
modified.
341fc4c
@Maks3w Maks3w commented on the diff
tests/ZendTest/Validator/StaticValidatorTest.php
@@ -96,7 +96,7 @@ public function testMaximumErrorMessageLength()
$loader = new TestAsset\ArrayTranslator();
$loader->translations = array(
- Alpha::INVALID => 'This is the translated message for %value%',
+ 'Invalid type given. String expected' => 'This is the translated message for %value%',
@Maks3w Collaborator
Maks3w added a note

Why this? If the constant does not aim to be readable then we can still relying in the value whatever it is.

Because we are not translating the validator message keys but the validator messages

In theory it would be nice to do $validator->templateMessages[Alpha::INVALID] => '...' but templateMessages is protected so it's not possiblo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney [#5664] Added note to README
- Like #5666, this is technically a BC break and needs a note in the changelog.
d8b9de6
@weierophinney weierophinney merged commit 341fc4c into zendframework:develop

1 check failed

Details default The Travis CI build failed
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-validator
@weierophinney weierophinney Merge pull request zendframework/zf2#5664 from macnibblet/hotfix/remo…
…ve-validator-message-key-translation

[Minor BC] Remove translation of validator keys
01f8a27
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-validator
@weierophinney weierophinney Merge branch 'hotfix/5664' into develop c418e80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 2, 2014
  1. @macnibblet

    [Minor BC] Remove translation of validator keys

    macnibblet authored
    Removes the translation of validator message ***keys*** which is totally
    absurd in the first place. They are constants that should not be
    modified.
This page is out of date. Refresh to see the latest.
View
7 library/Zend/Validator/AbstractValidator.php
@@ -575,13 +575,6 @@ protected function translateMessage($messageKey, $message)
return $message;
}
- $translated = $translator->translate(
- $messageKey, $this->getTranslatorTextDomain()
- );
- if ($translated !== $messageKey) {
- return $translated;
- }
-
return $translator->translate(
$message, $this->getTranslatorTextDomain()
);
View
22 tests/ZendTest/Validator/AbstractTest.php
@@ -76,28 +76,6 @@ public function testErrorMessagesAreTranslatedWhenTranslatorPresent()
$loader = new TestAsset\ArrayTranslator();
$loader->translations = array(
- 'fooMessage' => 'This is the translated message for %value%',
- );
- $translator = new TestAsset\Translator();
- $translator->getPluginManager()->setService('default', $loader);
- $translator->addTranslationFile('default', null);
-
- $this->validator->setTranslator($translator);
- $this->assertFalse($this->validator->isValid('bar'));
- $messages = $this->validator->getMessages();
- $this->assertTrue(array_key_exists('fooMessage', $messages));
- $this->assertContains('bar', $messages['fooMessage'], var_export($messages, 1));
- $this->assertContains('This is the translated message for ', $messages['fooMessage']);
- }
-
- public function testCanTranslateMessagesInsteadOfKeys()
- {
- if (!extension_loaded('intl')) {
- $this->markTestSkipped('ext/intl not enabled');
- }
-
- $loader = new TestAsset\ArrayTranslator();
- $loader->translations = array(
'%value% was passed' => 'This is the translated message for %value%',
);
$translator = new TestAsset\Translator();
View
2  tests/ZendTest/Validator/EmailAddressTest.php
@@ -420,7 +420,7 @@ public function testHostnameValidatorMessagesShouldBeTranslated()
$hostnameValidator = new Hostname();
$translations = array(
'hostnameIpAddressNotAllowed' => 'hostnameIpAddressNotAllowed translation',
- 'hostnameUnknownTld' => 'hostnameUnknownTld translation',
+ 'hostnameUnknownTld' => 'The input appears to be a DNS hostname but cannot match TLD against known list',
'hostnameDashCharacter' => 'hostnameDashCharacter translation',
'hostnameInvalidHostnameSchema' => 'hostnameInvalidHostnameSchema translation',
'hostnameUndecipherableTld' => 'hostnameUndecipherableTld translation',
View
2  tests/ZendTest/Validator/HostnameTest.php
@@ -261,7 +261,7 @@ public function testValidatorMessagesShouldBeTranslated()
}
$translations = array(
- 'hostnameInvalidLocalName' => 'this is the IP error message',
+ 'hostnameInvalidLocalName' => 'The input does not appear to be a valid local network name',
);
$loader = new TestAsset\ArrayTranslator();
$loader->translations = $translations;
View
3  tests/ZendTest/Validator/StaticValidatorTest.php
@@ -96,7 +96,7 @@ public function testMaximumErrorMessageLength()
$loader = new TestAsset\ArrayTranslator();
$loader->translations = array(
- Alpha::INVALID => 'This is the translated message for %value%',
+ 'Invalid type given. String expected' => 'This is the translated message for %value%',
@Maks3w Collaborator
Maks3w added a note

Why this? If the constant does not aim to be readable then we can still relying in the value whatever it is.

Because we are not translating the validator message keys but the validator messages

In theory it would be nice to do $validator->templateMessages[Alpha::INVALID] => '...' but templateMessages is protected so it's not possiblo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
);
$translator = new TestAsset\Translator();
$translator->getPluginManager()->setService('default', $loader);
@@ -105,6 +105,7 @@ public function testMaximumErrorMessageLength()
$this->validator->setTranslator($translator);
$this->assertFalse($this->validator->isValid(123));
$messages = $this->validator->getMessages();
+
$this->assertTrue(array_key_exists(Alpha::INVALID, $messages));
$this->assertEquals('This is...', $messages[Alpha::INVALID]);
}
Something went wrong with that request. Please try again.