Hugo
Hugo

Reputation: 504

Jqueryui dialog with multiple languages

I use jqueryui, dialog plugin with this code for example.

$( "#showUser-form" ).dialog(
                    {
                        buttons: {
                            "OK": function()
                            {
                                    $( this ).dialog( "close" );
                            },
                            cancel: function()
                            {
                                $( this ).dialog( "close" );
                            }
                        },
                        close: function() {}
                    });

How can I do to be able to change the text of button 'cancel' for example for a multilanguages website ?

Regards

Hugo

Upvotes: 2

Views: 1785

Answers (1)

Elliott
Elliott

Reputation: 2729

You have to create a new object to contain the buttons and pass it to the buttons parameter. Then you can dynamically set the text of the buttons.

jsFiddle Here

Like this:

//You can dynamically change button text here
var buttons = [,];
buttons['OK'] = 'OK :)';
buttons['Cancel'] = 'Cancel :(';

var buttonArray = {};
buttonArray[buttons['OK']] = function() {
    //Set OK function here
    $(this).dialog('close');
};
buttonArray[buttons['Cancel']] = function() {
    //Set Cancel function here
    $(this).dialog('close');
};


$(function () {
    $('#dialog').dialog({
        buttons: buttonArray
    });
});

Upvotes: 3

Related Questions