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

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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

#1 User is offline   raskae 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 09-September 13

Posted 09 September 2013 - 10:29 PM

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.

Example:

Nombre
<input text>
errorMessage: "pageName.lblNameField cannot be blank."

attributeLabels

translation file:
"appName/es.php"
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.
0

#2 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 840
  • Joined: 19-February 13

Posted 10 September 2013 - 01:26 AM

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

like

 //'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,
Ankit Modi
0

#3 User is offline   raskae 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 09-September 13

Posted 11 September 2013 - 08:10 AM

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?
0

#4 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 840
  • Joined: 19-February 13

Posted 12 September 2013 - 12:04 AM

View Postraskae, on 11 September 2013 - 08:10 AM, said:

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?
Thanks,
Ankit Modi
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users