Skip to Content

Getting i18n text in controller

Hi,

In dialog box i have sap.m.Text control

for that i have to set text which is there in i18n

i tried using below code its not working.

var dialogmasterlist = new sap.m.Dialog({

  title: 'Warning',

  type: 'Message',

  state: 'Warning',

  content: new sap.m.Text({

  text:"{i18n>notificationChangeAlert}"

  }),

  beginButton: new sap.m.Button({

  text: 'Yes',

press: function() {

       alert("Yes ");

       dialogmasterlist.close();

  }

}),

endButton: new sap.m.Button({

  text: 'No',

  press: function() {

       alert("NO");

       dialogmasterlist.close();

  }

  }),

});

In view its working problem only in controller.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Oct 28, 2015 at 12:15 PM

    You could try doing something like

    this.getView().getModel("i18n").getResourceBundle().getText("notificationChangeAlert");

    Regards,

    Jamie

    SAP - Technology RIG

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 28, 2015 at 01:27 PM

    Hi,

    You could also do it in the following way:

    getResourceText: function(sKey) {
      jQuery.sap.require("jquery.sap.resources");
      var sLocale = sap.ui.getCore().getConfiguration().getLanguage();
      var oBundle = jQuery.sap.resources({
      url: "i18n/messageBundle.properties",
      locale: sLocale
      });
      return oBundle.getText(sKey);
    }
    

    Then it´s independent from you view model.

    Best regards,

    Sebastian

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 28, 2015 at 06:46 PM

    xxx.i18n = function (property) {

       if (arguments.length > 1) {

       var text = sap.ui.getCore().getModel("i18n").getProperty(arguments[0]);

       if (text) {

       for (index = 1; index < arguments.length; ++index) {

       text = text.replace("{" + index + "}", arguments[index]);

      }

      }

       return text;

      }

       else {

       return sap.ui.getCore().getModel("i18n").getProperty(property);

      }

    };

    xxx.i18n("NAME_OF_THE_PROPERTY", param1, param2);//will replace {1} with value from param1 and {2} with param2 etc

    Add comment
    10|10000 characters needed characters exceeded