翻译 CodeIgniter 的表单验证错误消息
有没有办法在不接触系统文件的情况下翻译 CodeIgniter 的表单验证错误消息?
Is there anyway to translate CodeIgniter's form validation error messages without touching to system files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您正在谈论实际翻译成另一种语言,可以通过将配置值
$config['language']
设置为您想要的语言来完成。如果您不想更改实际的 config.php 文件,您可以通过使用 Config 对象的set_item()
函数来完成此操作,如下所示:请参阅:配置类的 CodeIgniter 文档
这假设您的
language
目录中有一个西班牙语目录,其中至少包含form_validation_lang.php
文件。但是,如果您只想为 Form_validation 对象创建自定义消息,则可以从
system\language
目录复制form_validation_lang.php
文件并将其移动到 <代码>应用程序\语言目录。您现在可以编辑新的语言文件,使其反映您想要的任何不同消息。您还可以通过从application/language
目录中删除文件来轻松恢复默认消息。如果您甚至不想触及
语言
文件,另一种方法是手动覆盖消息。您可以通过Form_validation
库对象来完成此操作,如下所示:请参阅:表单验证类的 CodeIgniter 文档
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'sset_item()
function like this:See: CodeIgniter Doc for the Config Class
This assumes that you have a spanish directory in your
language
directory with at least theform_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 thesystem\language
directory and move it to theapplication\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 theapplication/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 theForm_validation
library object like so:See: CodeIgniter Doc for the Form Validation Class
如果您需要为某些特定规则的特定字段设置自定义错误消息,请使用 set_rules() 方法:
这将独立解决您的所有字段问题。 :)
If you need to set a custom error message for a particular field on some particular rule, use the set_rules() method:
This will solve your all fields problem independently. :)