Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cakephp 2.0 Localization for Model Messages

I am trying to get i18n to extract the strings from my model in Cakephp 2.0

The documentation states that "CakePHP will automatically assume that all model validation error messages in your $validate array are intended to be localized. When running the i18n shell these strings will also be extracted." http://book.cakephp.org/2.0/en/core-libraries/internationalization-and-localization.html But my messages in my model are not being extracted into my po file when I run cake i18n and extract the data.

Does anyone know how to get the message strings into the po file?

App::uses('AuthComponent', 'Controller/Component');
class User extends AppModel {
 public $validate = array(
        'username' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'A Username is required',
                 'rule' => 'isUnique',
                'message' => 'This username has already been taken'
            )
);
}
like image 232
O F Avatar asked Dec 13 '22 02:12

O F


1 Answers

This is how you can solve the problem I came across.

App::uses('AuthComponent', 'Controller/Component');
        class User extends AppModel {
         function __construct() {
                parent::__construct();
                $this->validate = array(
                'username' => array(
                    'required' => array(
                        'rule' => array('notEmpty'))
                        'message' => __('A Username is required', true)), 
                      'unique' => array(
                        'rule' => 'isUnique',
                        'message' => _('This username has already been taken', true)
                    )
        );}
        }
like image 113
O F Avatar answered Dec 18 '22 21:12

O F