Translate "Buttons" in jQuery UI Dialogs
Asked Answered
G

4

7

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.

Gromwell answered 8/4, 2011 at 6:7 Comment(0)
M
8

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.

Mashie answered 8/4, 2011 at 6:13 Comment(1)
+1 this is how I do translation throughout jQuery UI. We need to change a little bit of our code, but works like a charm.Hightower
S
3

There are two ways to specify buttons in a dialog (since 1.8.5). Only one of them is useful for internationalization. Define your options like this:

if (data.status == 'success') {
    options = {
        buttons: [{
            text: CLOSE,
            click: function() {
                      $(this).dialog('close');
                   }
        }]
    }
}

@dioslaska's solution works as well, but I think this way is prettier.

Sg answered 26/8, 2011 at 12:0 Comment(1)
I prefer this answer too since it is more obvious where the translations are coming from.Millsap
S
0

Just put in in quotation marks :P

if (data.status == 'success') {
  options = {
    buttons: {
      'translated text for close': function() {
                  $(this).dialog('close');
               }
       }
  };
Sextodecimo answered 8/4, 2011 at 6:9 Comment(1)
The translations are stored in an JS file like: var CLOSE = 'Schließen'; so your solution wont work.Gromwell
F
0

You must modify the declaration of the Dialog widget in jquery-ui javascript file.

Find the line

closeText: "Close",

and replace "Close" with your translation.

Feces answered 30/9, 2016 at 14:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.