If you are talking about translating into another language, this can be done by setting the configuration value $config['language']
to the desired language. If you do not want to modify the actual config.php file, you can do this using the Config object set_item()
function as follows:
$this->config->set_item('language', 'spanish');
See: CodeIgniter Doc for configuration class
It is assumed that you have a Spanish directory in the language
directory, at least with the form_validation_lang.php
file.
However, if you just want to create your own messages for the Form_validation object, you can copy the form_validation_lang.php
file from the system\language
directory and transfer it to the application\language
directory. Now you can edit the new language file to reflect any other messages that you want. You can also easily revert to default messages by deleting the file from the application/language
directory.
Another way to do this if you do not want to touch even language
files is to manually redefine the messages. You can do this through the library object Form_validation
as follows:
$this->form_validation->set_message('required', 'This is a required item!');`
See: CodeIgniter Doc for form validation class
Wes crow
source share