问题
I found how to i18n the message of the submit button like :
echo CHtml::submitButton(Yii::t('tr','Print'),array('confirm'=>Yii::t('tr','Please confirm printing'),));
Then setting language also translate well the system messages but how to translate the CANCEL / OK buttons of the submit confirm pop up message box ?
回答1:
An alternate solution using CJuiDialog:
Code for the jqueryui dialog(CJuiDialog is a wrapper with some additional yii specifics):
<?php $this->beginWidget('zii.widgets.jui.CJuiDialog', array( 'id'=>'mydialog', // additional javascript options for the dialog plugin 'options'=>array( 'title'=>Yii::t('tr', 'Title'), 'autoOpen'=>false, 'modal'=>true, 'closeOnEscape'=>true, 'closeText'=>Yii::t('tr', 'Cancel'), 'resizable'=>false, 'buttons'=>array( Yii::t('tr', 'Ok')=>'js:function(){$("#myform-id").submit();$(this).dialog("close");}', Yii::t('tr', 'Cancel')=>'js:function(){$(this).dialog("close");}' ) ), )); echo Yii::t('tr','Please confirm printing'); $this->endWidget('zii.widgets.jui.CJuiDialog'); ?>
Make this dialog appear for the
onclick
event of the submit button:echo CHtml::submitButton(Yii::t('tr','Print'),array('onclick'=>'$("#mydialog").dialog("open"); return false;'));
Ofcourse this dialog will not look anything like the default browser/js confirm dialog, but it can be used if required. As already mentioned by ors in the comments, the default confirm dialog can not be changed, and a localized browser should have localized messages.
In this sample i have just submitted a form with id myform-id
, however anything can be done in the ok button's function.
来源:https://stackoverflow.com/questions/11200224/yii-submitbutton-i18n