Validation Error Message {Attribute} Not Loading Yii:t()

I have a problem with validation error messages, when using yii::t() with a translation file. I have the attribute labels array set to load the name of the attribute from the file and that works like intented, in the forms it shows the message perfectly, except when a validation error happens, in which case the error message shows the key not the message.



<input text>

errorMessage: "pageName.lblNameField cannot be blank."


translation file:


return array(

    'pageName.lblNameField' => 'Nombre',


Model class:

public function attributeLabels() {

   return array(

      'nameField' => Yii::t('appName', 'pageName.lblNameField '),



Any help about how or what should i do so the validation errors load the correct value of the attribute label?

Thanks in advance.

you can defind the lanaguages on config/main.php file.


 //'sourceLanguage'    =>'en_US',

    'language'          =>'en_US',

or i think you can create the es.php file so write look like something

return array(

      'nameField' => Yii::t('es', 'pageName.lblNameField '),


Thanks a lot Ankit, setting the language directly in the config/main file did quite solve that issue, of loading the attribute labels correctly when a validation error occurred. But it brings me to another one, i’m setting the language at page load through Yii::app()->setLanguage( Yii::app()->getRequest()->getPreferredLanguage() ). In wich case i still have the same problem as before, it doesnt load the attribute labels in validation error messages.

Is there any other way i could specify the language dinamically from browser? or any other way to set language?

Hi As per your message i think i undestand the you want to change the form lable?correct?