How can I use Yii 1.1 translation inside a CJavaScriptExpression?

106 Views Asked by At

I have the following code:

<?php 
    $this->widget('zii.widgets.jui.CJuiButton',array(
    'name'=>'save',
    'caption'=>Yii::t('app', 'Save'),
    'htmlOptions'=>array(
        'style'=>'
                 background: #EA7500;
                 color: white;',
    ),
    'onclick'=>new CJavaScriptExpression(
        'function(){
            swal("Saved", 
                "Successfully saved", 
                "success");
            saveInputFunction();
            return false;
        }'
    ),
)); ?>

I want to translate "Saved" and "Successfully saved" using Yii::t("app", "Saved"), however I'm not finding the correct syntax.

1

There are 1 best solutions below

0
leob On BEST ANSWER

I called a js function in 'onclick' parameter and sent the translated message via ajax using an action that I wrote in the controller.

<?php
    $this->widget('zii.widgets.jui.CJuiButton',array(
        'name'=>'save',
        'caption'=>Yii::t('app', 'Save'),
        'htmlOptions'=>array(
            'style'=>'
                 background: #EA7500;
                 color: white;',
        ),
        'onclick'=>'js:function(){
                        updateInput();
                        return false;
                    }',
    )); 
?>


<script>
    function updateInput(){
        //code
    }
</script>