Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 605
curious1 Avatar asked Oct 16 '13 02:10

curious1


2 Answers

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",
});
like image 96
bool.dev Avatar answered Sep 22 '22 08:09

bool.dev


OR use localization - option, to change ALL Buttons per Default:

    bootbox.setDefaults({
          /**
           * @optional String
           * @default: en
           * which locale settings to use to translate the three
           * standard button labels: OK, CONFIRM, CANCEL
           */
          locale: "de"
    });

seen: http://bootboxjs.com/documentation.html, "Helper methods"

like image 32
Sarah Trees Avatar answered Sep 25 '22 08:09

Sarah Trees