Search code examples
jquerybuttoninternationalizationtranslationjquery-ui-dialog

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.


Solution

  • 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.