![]() |
validation_errors() in a multilingual site? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: validation_errors() in a multilingual site? (/showthread.php?tid=30383) |
validation_errors() in a multilingual site? - El Forum - 05-13-2010 [eluser]chefnelone[/eluser] Hello, I've done a validation and it works fine. But my site is multilingual and the validation_errors() always shows the error in JUST one language: Spanish; even if changed to English. I have the rigth folders 'spanish' and 'english' in applications/languages. I need it to show the errors in english. When I switch language, let's say to 'english' I set: Code: $this->session->userdata('language')='english'; Then if $this->session->userdata('language'); is set to 'english', then validation_errors(); should shows the errors in english. Am I right? Code: $this->firephp->log( $this->session->userdata('language') );// THIS OUTPUT 'english' validation_errors() in a multilingual site? - El Forum - 05-13-2010 [eluser]WanWizard[/eluser] The language loaded is the one you define in your application config/config.php file. You can switch languages at runtime by using: Code: $this->config->config['language'] = 'english'; validation_errors() in a multilingual site? - El Forum - 05-13-2010 [eluser]chefnelone[/eluser] [quote author="WanWizard" date="1273759879"]The language loaded is the one you define in your application config/config.php file. You can switch languages at runtime by using: Code: $this->config->config['language'] = 'english'; Thanks wanwizard, just one more thing. if I have this line: Code: $this->form_validation->set_rules('phone', '', 'required'); the error output is: 'The phone field is required.' where 'phone' is the name of the input Then, if I change the language to 'spanish' it still shows 'phone' in the spanish error output: 'El campo phone es requerido.' the word 'phone' doesn't make any sense here. Is there any way to set the second parameter of set_rules() to allow me to set it dynamically (based in the language)? validation_errors() in a multilingual site? - El Forum - 05-13-2010 [eluser]WanWizard[/eluser] You can use the following syntax: Code: $this->form_validation->set_rules('phone', 'lang:field_phone', 'required'); Then, add the language string 'field_phone' to your languages files, where the english one translates to 'phone', and the spanish one to 'teléfono'. I usually use the same language string here as I use in the form, so the name in the message always matches whatever the label of the form field is. validation_errors() in a multilingual site? - El Forum - 05-13-2010 [eluser]chefnelone[/eluser] many thanks |