Gaucho_9
Gaucho_9

Reputation: 265

Validation messages showing translations problems with cakephp

I'm trying to internationalize my project with cakephp validation messages. The file generation .pot and later .po seems to be correct, the problem is when in the view the validation error is shown, the default message (written on the model) is always shown, do not get the message language file.

I tried two ways to extract messages:

cake i18n extract
OR
cake i18n extract --validation-domain validation

In my AppController I have:

public function beforeFilter() {
    $this->Session->write('Config.language', 'spa');
}

In my Locale directory I have:

Locale / spa / LC_MESSAGES / default.po
                             validation.po

In my PostModel I have:

class Post extends AppModel {

 public $validationDomain = "validation";

  public $validate = array(
    'text' => array(
        'required' => array(
            'rule' => array('notEmpty'),
            'message' => '* Aquest camp és obligatori' //* This field is required -> in spanish -> Este campo es obligatorio            
        )
    )
  ); 
}

I'm using JqueryValidationHelper.php and I create the inputs like this:

<?php echo $this->jQueryValidation->input('text', array('required'));?>

I missing something?? I have to tell cakephp where my validation messages are?? All the messages in default.po are shown correctly, I don't know what's going on whith validation messages...

Thanks


SOLUTION

I edit the row in the file JqueryValidationHelperand the method meta():

if (!empty($validateParams['message'])) {
    $msg = $validateParams['message'];
}

for

 if (!empty($validateParams['message'])) {
        $msg = __d('validation',$validateParams['message']);
 }

Take care to use __d() or __() depending how you extract you messages in cake i18n extract (in default.po) or if you define a public $validationDomain = "validation"; in your Models.

Upvotes: 0

Views: 1193

Answers (1)

ndm
ndm

Reputation: 60483

Judging from the source, the helper doesn't respect translations, it just grabs the raw values defined in the validation rules, see JqueryValidationHelper::meta().

I'd suggest to create an issue ticket and request for adding proper translation support as can be seen in CakeValidationSet::_processValidationResponse(). Or just add it yourself...

Upvotes: 1

Related Questions