Is there anyway to translate CodeIgniter\'s form validation error messages without touching to system files?
If you are talking about actually translating to another language, this can be done by setting the config value $config['language']
to the language you want. If you don't want to change the actual config.php file you can do it through the use of the Config object's set_item()
function like this:
$this->config->set_item('language', 'spanish');
See: CodeIgniter Doc for the Config Class
This assumes that you have a spanish directory in your language
directory with at least the form_validation_lang.php
file.
However, if you are just wanting to create custom messages for the Form_validation object, you can copy the form_validation_lang.php
file from the system\language
directory and move it to the application\language
directory. You can now edit the new language file to make it reflect any different messages you want. You can also revert back to the default messages easily by removing the file from the application/language
directory.
Another way to do it, if you don't want to touch even the language
files is to manually override the messages. You can do that through the Form_validation
library object like so:
$this->form_validation->set_message('required', 'This is a required item!');`
See: CodeIgniter Doc for the Form Validation Class