0
我需要根據語言更改更改錯誤消息。在Cakephp中更改多語言錯誤消息
我已經在/locale/en/LC_MESSAGES/default.po
創建default.po
文件在已經創建MSGID爲ID-1和相同的方式
這樣做是爲了西班牙
/locale/spa/LC_MESSAGES/default.po
在視圖文件:
<label class="control-label"><?php echo __('ID-1'); ?><span class="red">*</span></label>
<div class="controls">
<?php echo $this->Form->input('Patient.fname', array('label' => false,'required'=>true, 'div' => false,'Placeholder' => 'First Name','class'=>'','maxlength'=>'20','size'=>"30")); ?>
</div>
控制器:
if ($this->request->is('ajax')) {
if (!empty($this->request->data)) {
$this->Patient->save($this->request->data);
}
}
和型號文件:
App::uses('Model', 'Model');
/**
* Application model for Cake.
*
* Add your application-wide methods in the class below, your models
* will inherit them.
*
* @package app.Model
*/
class Patient extends Model {
var $useTable = 'patients';
var $actsAs = array('Logable');
var $validate = array(
'fname' => array(
'required' => array(
'rule' => 'notEmpty',
'message' => "Please Enter Your FristName."
)
),
}
}
所以當我改變從英語到西班牙那段時間,模型驗證錯誤消息都沒有得到更改。
任何人都可以幫我解決這個問題嗎?
這不是OP想要的,他無法翻譯驗證消息。 –
模型驗證消息在內部調用__()。因此,如果翻譯根本不起作用,那麼OP的問題必須出現在其他地方:locale設置不正確,錯誤的po/mo文件等:因此我的「評論」。 順便說一下,OP可能希望從AppModel繼承而不是Model。 – JDR
他說「MODEL VALIDATION ERROR MESSAGES不會改變。」 這意味着剩下的字符串正在被翻譯。所以可能有另一種翻譯驗證信息的方法。 –