Temat: Języki w modelach (wiadomości walidacji)

var $validate = array(
        'username' => array(
            'The username must be between 5 and 15 characters.' => array(
                'rule' => array('between', 5, 15),
                'message' => 'The username must be between 5 and 15 characters.'
            ),
            'That username has already been taken' => array(
                'rule' => 'isUnique',
                'message' => 'That username has already been taken.'
            )
        ),
        'password' => array(
            'The password must be between 5 and 15 characters.' => array(
                'rule' => array('between', 5, 15),
                'message' => 'The password must be between 5 and 15 characters.'
            ),
            'The passwords do not match.' => array(
                'rule' => 'matchPasswords',
                'message' => 'The passwords do not match.'
            )
        )
    );

I jak tu zrobić langi?

2

Odp: Języki w modelach (wiadomości walidacji)

Ok odpowiedzieli mi na ask.cakephp.org.
Wiadomość w j. ang.:

Create a new file on your locale->{you language}->LC_MESSAGES , a call it validation-errors.po

---------------------------- This is my example

##########################################
#: Error Messages
##########################################

msgid "The username must be between 5 and 15 characters."
msgstr "{your message here}"

and add invalidade method to your AppModel

class AppModel extends Model {
function invalidate($field, $value = true) {
return parent::invalidate($field, __d('validation-errors', $value, true));
}
}

please make sure that the first parameter to __d function is the name of your po file without extention

Ostatnio edytowany przez Saibamen (2011-06-13 18:44:30)

3

Odp: Języki w modelach (wiadomości walidacji)

Jest też inny sposób:

public function __construct($id = false, $table = null, $ds = null) {
        parent::__construct($id, $table, $ds);
        $this->validate = array(
            'username' => array(
                'required' => array(
                    'rule' => array('notEmpty'),
                    'allowEmpty' => false,
                    'message' => __d('fe', 'To pole nie może być puste', true)
                )
            ),
            'email' => array(
                'required' => array(
                    'rule' => array('notEmpty'),
                    'allowEmpty' => false,
                    'message' => __d('fe', 'To pole nie może być puste', true)
                ),
                'isValid' => array(
                    'rule' => 'email',
                    'message' => __d('fe', 'Wprowadź poprawny adres e-mail', true)
                )
            )
        );
    }

w modelu oczywiście.

Ostatnio edytowany przez Eliard (2011-07-12 11:59:19)