Yii submitButton i18n

时光毁灭记忆、已成空白 提交于 2019-12-12 16:31:26

问题


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:

  1. 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');
    ?>
    
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!