翻译CodeIgniter的表单验证错误消息 [英] Translating CodeIgniter's form validation error messages
问题描述
有没有反正翻译CodeIgniter的表单验证错误消息,而不接触系统文件?
Is there anyway to translate CodeIgniter's form validation error messages without touching to system files?
推荐答案
可以通过将配置值 $ config ['language']
设置为所需的语言来完成。如果你不想改变实际的config.php文件,你可以通过使用Config对象的 set_item()
函数这样做:
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');
这假设您的语言
目录中至少有 form_validation_lang.php
文件。
This assumes that you have a spanish directory in your language
directory with at least the form_validation_lang.php
file.
但是,如果你只是想创建自定义Form_validation对象的消息,您可以从 system\language
目录中复制 form_validation_lang.php
文件,到 application\language
目录。您现在可以编辑新的语言文件,使其反映您想要的任何其他消息。您还可以通过从应用程序/语言
目录中删除该文件,轻松地还原为默认邮件。
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.
方法来做,如果你不想触摸即使语言
文件是手动覆盖消息。你可以通过 Form_validation
库对象来这样做:
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!');`
$ b b
这篇关于翻译CodeIgniter的表单验证错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!