How to localise buttons on JQueryUI modal dialog

懵懂的女人 提交于 2019-12-05 05:29:20

You just change the name of the property...

var buttons = {};
buttons[getLocalizedCaptionForYesButton()] = function() { };
buttons[getLocalizedCaptionForCancelButton()] = function() { };

$("#MyDialog").dialog({
    buttons: buttons
});

The best way to localize buttons is to use the array format for the buttons option.

$( "#MyDialog" ).dialog({
    buttons: [
        {
            text: "OK",
            click: function() { ... }
        },
        {
            text: "Cancel",
            click: function() { ... }
        }
    ]
});

This makes it natural to work with dynamic labels. With this format, you can also specify any other attributes, such as class, disabled, etc.

http://api.jqueryui.com/dialog/#option-buttons

Alfamale

OK, found the way to do this: you need to create one object with you translations in it (this object can be passed into the function) and then create a second object that ties your action functions to the elements of the translations objects:

var translations = {};
translations["ok"] = "Si";
translations["cancel"] = "Cancellare";

var buttonsOpts = {};
buttonsOpts[translations["ok"]] = function () {
            .
            .
            .
        };
buttonsOpts[translations["cancel"]] = function () {
            .
            .
            .
        };

$("#MyDialog").dialog({
    .
    .
    .
    buttons: buttonsOpts
});

Basic answer provided by Alexey Ogarkov to question jQuery UI Dialog Buttons from variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!