Bootbox 4.1.0: how to pass localized strings such as Ok, Cancel to Bootbox's confirm?

curious1 picture curious1 · Oct 16, 2013 · Viewed 8.7k times · Source

In Bootbox 3.2.0, I was able to use confirm with strings passed as below:

bootbox.confirm(
    confirm_string, 
    cancel_string, 
    yes_string,
    function(r) {           
        if (r) {
            //do something
        }
    }
);

I am upgrading to 4.1.0 and I got errors with the above function call.

According to the documentation (http://bootboxjs.com/documentation.html) of Bootbox 4.1.0, there are two ways to call confirm:

bootbox.confirm(str message, fn callback)    
bootbox.confirm(object options)

I tested the fist way with the message string and a callback function and it works. For the second way, I was able to pass an object as follows:

{
  message: message_string
  callback: function(r) {
    //do something
  }
}

How can I pass strings for OK, Cancel buttons in the second way?

Thanks and regards.

Answer

bool.dev picture bool.dev · Apr 22, 2014

As an alternative this can also be done directly with bootbox.confirm, like so:

bootbox.confirm({
    buttons: {
        confirm: {
            label: 'Localized confirm text',
            className: 'confirm-button-class'
        },
        cancel: {
            label: 'Localized cancel text',
            className: 'cancel-button-class'
        }
    },
    message: 'Your message',
    callback: function(result) {
        console.log(result);
    },
    title: "You can also add a title",
});