如何同时使用两种不同语言的codeigniter表单验证库?

问题描述:

我试图使用笨表单验证库显示在同一时间在两个不同语言的两个不同行,但它抛出一个错误:如何同时使用两种不同语言的codeigniter表单验证库?

$this -> form_validation -> set_message('required', 'Warning %s should not be empty! <br /> Dikkat %s alanı boş bırakılmamalıdır.'); 

有没有办法使用像这样的功能,无需面对那个错误:

A PHP Error was encountered 

Severity: Warning 

Message: sprintf(): Too few arguments 

Filename: libraries/Form_validation.php 

Line Number: 525 

core/libraries/form_validation.php中525行的sprintf()函数只有两个参数。

$message = sprintf($line, $this->_translate_fieldname($row['label'])); 

第一个参数必须是带指定插入点的字符串。以下参数(在sprintf函数中)必须与插入点的数量相匹配。而codeigniter只使用一个。

从笨Userguide:http://ellislab.com/codeigniter/user_guide/libraries/form_validation.html

If you include %s in your error string, it will be replaced with the "human" name you used for your field when you set your rules.

但是,对于你的问题的解决方案是这样的:

$this->form_validation->set_message('required', 'Warning %1$s should not be empty! <br /> Dikkat %1$s alanı boş bırakılmamalıdır.'); 

%1个$ s表示在sprintf的字符串参数后的第一个参数()。它是在例子很好的解释在这里:http://dk1.php.net/sprintf

+0

我用你的建议,但错误仍然是same.A PHP错误遇到 严重性:警告 消息:的sprintf():参数太少 文件名:库/ Form_validation.php 行号码:525 – motto

+0

Aha%2 $ s无法正常工作,但%1 $ s工作正常!你是怎么想出来的?那背后的逻辑是什么?我很好奇 – motto

+1

格言:我已经编辑了一个链接到PHP手册的答案。这些例子很好地解释了它。 – nielsiano