Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translate "Buttons" in jQuery UI Dialogs

I have two JavaScript files with translations, which will be included depending on the users language. This works fine for most cases. But not for the Buttons object inside an jQuery UI Dialog. Any ideas how to solve this?

if (data.status == 'success') {
    options = {
        buttons: {
            CLOSE: function() {
                      $(this).dialog('close');
                   }
            }
        };

CLOSE must be translated.

like image 823
opHASnoNAME Avatar asked Apr 08 '11 06:04

opHASnoNAME


2 Answers

Create the buttons object like this:

var myButtons = {};
myButtons[CLOSE] = function() { $(this).dialog('close'); };

if (data.status == 'success') {
  options = {
    buttons: myButtons
  };
}

Edit: Updated to use the CLOSE variable.

like image 56
istvan.halmen Avatar answered Oct 05 '22 23:10

istvan.halmen


There are two ways to specify buttons in a dialog (since 1.8.5). Only one of them is useful for internationalization. Define your options like this:

if (data.status == 'success') {
    options = {
        buttons: [{
            text: CLOSE,
            click: function() {
                      $(this).dialog('close');
                   }
        }]
    }
}

@dioslaska's solution works as well, but I think this way is prettier.

like image 36
itsadok Avatar answered Oct 06 '22 01:10

itsadok