Question

I need to change the error messages based on the language changes.

i have created default.po file in the /locale/en/LC_MESSAGES/default.po

in that have created msgid as ID-1 and same way

did it for spain

/locale/spa/LC_MESSAGES/default.po

in view file:

<label class="control-label"><?php echo __('ID-1'); ?><span class="red">*</span></label>
                    <div class="controls">
                                            <?php echo $this->Form->input('Patient.fname', array('label' => false,'required'=>true, 'div' => false,'Placeholder' => 'First Name','class'=>'','maxlength'=>'20','size'=>"30")); ?> 
                    </div>

controller:

 if ($this->request->is('ajax')) {

            if (!empty($this->request->data)) {

                $this->Patient->save($this->request->data);
}
}

and Model file:

App::uses('Model', 'Model');


/**
 * Application model for Cake.
 *
 * Add your application-wide methods in the class below, your models
 * will inherit them.
 *
 * @package       app.Model
 */
class Patient extends Model {

    var $useTable = 'patients';
    var $actsAs = array('Logable');

    var $validate = array(
             'fname' => array(
            'required' => array(
                'rule' => 'notEmpty',
                'message' => "Please Enter Your FristName."
            )
        ),
}
}

so when i change language from English to spain that time, MODEL VALIDATION ERROR MESSAGES ARE NOT GETTING CHANGE.

Can anyone help me out in this?

Was it helpful?

Solution

I cannot comment, hence an answer. But did you set the app's language in AppController::beforeFilter()?

 Configure::write('Config.language', 'spa');

In a production environment, you would obviously set that value according to each user's individual preferences.

EDIT:

Okay, upon another look I may have misunderstood you. Please try the following in your model:

function __construct($id = false, $table = null, $ds = null) { 
    $this->validate['fname']['required']['message'] = __('Please Enter Your FristName.');
    parent::__construct($id = false, $table = null, $ds = null); 
} 

If this works, then something strange is going on with your CakePHP installation since validation-messages should internally automatically call __().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top