【问题标题】:Bootbox 4.1.0: how to pass localized strings such as Ok, Cancel to Bootbox's confirm?Bootbox 4.1.0:如何将Ok、Cancel等本地化字符串传递给Bootbox的确认?
【发布时间】:2013-10-16 02:17:14
【问题描述】:

在 Bootbox 3.2.0 中,我可以使用以下传递的字符串进行确认:

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

我正在升级到 4.1.0,但上述函数调用出现错误。

根据Bootbox 4.1.0的文档(http://bootboxjs.com/documentation.html),调用confirm有两种方式:

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

我用消息字符串和回调函数测试了第一种方式,它可以工作。对于第二种方式,我能够按如下方式传递一个对象:

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

如何以第二种方式传递 OK、Cancel 按钮的字符串?

感谢和问候。

【问题讨论】:

  • 没有人知道如何为“确定”和“取消”按钮传递本地化字符串?

标签: javascript bootbox


【解决方案1】:

作为替代方案,也可以直接使用bootbox.confirm 完成,如下所示:

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",
});

【讨论】:

    【解决方案2】:

    或使用本地化 - 选项,更改默认的所有按钮:

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

    看到:http://bootboxjs.com/documentation.html,“辅助方法”

    【讨论】:

      【解决方案3】:

      您可以使用“自定义对话框”(bootbox.dialog) 来更改这些字符串。

      bootbox.dialog({
        message: "Custom message",
        title: "Custom title",
        buttons: {
          danger: {
            label: "Custom Cancel",
            className: "btn-danger",
            callback: function() {
              //do something
            }
          },
          main: {
            label: "Custom OK",
            className: "btn-primary",
            callback: function() {
              //do something else
            }
          }
        }
      });
      

      【讨论】:

        猜你喜欢
        • 2018-05-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多