Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fix validation error domain for notEmpty #890

Merged
merged 1 commit into from

5 participants

Mark S. ADmad Mark Story José Lorenzo Rodríguez Andy Dawson
Mark S.
Collaborator

see http://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/3176-default-validation-message

I just run into the same issue upgrading a 1.3 app to 2.x

public $validate = array(
    'firstname' => array('notEmpty'),
    'lastname' => array('notEmpty'),
);

worked just fine in 1.x and translated the rule "notEmpty" via po file and "This field cannot be left blank" (eng) to "Plichtfeld" (deu).
With 2.x the returned message stays "This field cannot be left blank" (not translated).
so if we allow the flat (simple) array, we should make sure the rule gets not only the correct message but also the translated one.
I think the main issue is that it should NOT be the cake_dev domain:

$message = __d('cake_dev', 'This field cannot be left blank');

but

$message = __d('cake', 'This field cannot be left blank');

since it is user land code relevant and visible to the outside.

ADmad
Collaborator

If changing domain is necessary then changing it to $this->_validationDomain would be a better option since all your other validation messages would be in that domain.

Mark S.
Collaborator

thats true. i will update it.

Mark Story
Owner

Looks good to me :shipit:

Mark S.
Collaborator

I even squashed it right, imagine that! :)

José Lorenzo Rodríguez
Owner

This will break automatic parsing of messages, it makes more sense to use cake as the original commit was

Andy Dawson
Collaborator

It's not a developer message, including it in 'cake_dev' means it's in the po file with such gems as:

"Read the changelog"
"Your tmp directory is writable."
"MootoolsEngine::drop() requires a \"drag\" option to properly function"

and some 500ish other messages, all of which are 0% important to the end user.

There aren't any parsable 'default' domain messages in the core at all, and generally speaking there shouldn't be - that's what the cake domain was for: end user text that is in the core.

As such I agree with mark's original suggestion:

$message = __d('cake', 'This field cannot be left blank');
ADmad
Collaborator

If the general consensus is for using "cake" domain I am fine with it.

Mark Story
Owner

I totally missed that using the property name would break i18n parsing. Good catch @lorenzo.

Mark S. dereuromark fix validation error domain for notEmpty
$this->_validationDomain for default notEmpty message

notEmpty default error message
e85b2a0
Mark S.
Collaborator

looks ok then. even if I now may commit, I would still feel more comfortable with somebody else merging it in ;) unless you specifically instruct me to do so, anyway.

Mark Story markstory merged commit 4acc687 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 7, 2012
  1. Mark S.

    fix validation error domain for notEmpty

    dereuromark authored
    $this->_validationDomain for default notEmpty message
    
    notEmpty default error message
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/Cake/Model/Validator/CakeValidationSet.php
2  lib/Cake/Model/Validator/CakeValidationSet.php
View
@@ -280,7 +280,7 @@ protected function _processValidationResponse($name, $rule) {
$message = __d($this->_validationDomain, $name);
}
} else {
- $message = __d('cake_dev', 'This field cannot be left blank');
+ $message = __d('cake', 'This field cannot be left blank');
}
return $message;
Something went wrong with that request. Please try again.