Welcome Guest, Not a member yet? Register   Sign In
validation_errors() in a multilingual site?
#1

[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'
$this->form_validation->set_rules('name', 'Name', 'required');
if ($this->form_validation->run() == FALSE) {
echo $errors = validation_errors();// BUT THIS OUTPUT IS IN 'spanish'
}
#2

[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';
#3

[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';
[/quote].

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)?
#4

[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.
#5

[eluser]chefnelone[/eluser]
many thanks




Theme © iAndrew 2016 - Forum software by © MyBB