CodeIgniter Forums
Sets of rules - Translation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Sets of rules - Translation (/showthread.php?tid=49915)



Sets of rules - Translation - El Forum - 03-07-2012

[eluser]Mauricio de Abreu Antunes[/eluser]
Hello,

I need help with this problem:
I have sets of rules for form validation. But i need to translate field in messages. I know how to translate error messages, but labels not (with sets/groups http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html).

Any idea?


Sets of rules - Translation - El Forum - 03-07-2012

[eluser]Kamarg[/eluser]
Prefix your label with "lang:" in your validation rule. For example, if you have a field in your language file called "field_label_1" your validation rule label would be "lang:field_label_1".


Sets of rules - Translation - El Forum - 03-07-2012

[eluser]Mauricio de Abreu Antunes[/eluser]
Code:
$config = array(
               array(
                     'field'   => 'username',
                     'label'   => 'Username',
                     'rules'   => 'required'
                  ),
               array(
                     'field'   => 'password',
                     'label'   => 'Password',
                     'rules'   => 'required'
                  ),
               array(
                     'field'   => 'passconf',
                     'label'   => 'Password Confirmation',
                     'rules'   => 'required'
                  ),  
               array(
                     'field'   => 'email',
                     'label'   => 'Email',
                     'rules'   => 'required'
                  )
            );

If i put lang in 'label' index, does it work?


Sets of rules - Translation - El Forum - 03-07-2012

[eluser]Kamarg[/eluser]
Yes. You want "lang:" at the start of each of those label fields.


Sets of rules - Translation - El Forum - 03-07-2012

[eluser]Mauricio de Abreu Antunes[/eluser]
Thanks, gonna try out this! :-)