1

In my UI5 application, I have an i18n.properties file with keys and values:

#XMSG:
qty=Quantity

And I'm using this property value in a dialog box as title

onUpdateDialog: function() {
  var that = this;
  var dialog = new Dialog({
    title: "{i18n>qty}",
    // ...,
  });
  dialog.open();
},

But when I run my application, the dialog box title is not getting displayed:

enter image description here

When I use text values from i18n property file somewhere else it's getting displayed.

1

3 Answers 3

1

ManagedObjects, that are created by the application code imperatively outside of the framework-managed features (Such creating an instance of sap.m.Dialog in a Controller code without using the API loadFragment), have to be added to the model delegation chain manually in order to make use of the propagated models.

In order to do so, add the created instance to the parent's <dependents> aggregation. E.g.:

this.getView().addDependent(myDialog); // myDialog is now aware of the "i18n" model

From API Reference:

Special aggregation dependents is connected to the lifecycle management and databinding, but not rendered automatically and can be used for popups or other dependent controls or elements. This allows the definition of popup controls in declarative views and enables propagation of model and context information to them.

1
1

In order to use texts in the controller you need to fetch the text first, like so:

this.getOwnerComponent().getModel("i18n").getResourceBundle().getText("qty")   

this will be the dialog inside the dialog, so declare a that before the dialog and change this to that..

var that = this;
that.getOwnerComponent().getModel("i18n").getResourceBundle().getText("qty")

Hope this solves your issue..

3
  • it gives assignment.controller.js?eval:500 Uncaught TypeError: that.getResourceBundle is not a function Mar 27, 2018 at 8:34
  • Hi Tarzanbappa, Ofocurse it does, my bad :-) It's because getResourceBundle lives in my BaseController.. this.getOwnerComponent().getModel("i18n").getResourceBundle().getText("qty") is the correct code (or should be) Corrected this in previous answer Mar 27, 2018 at 8:59
  • Calling getText retrieves the text from the bundle which can be assigned to the title property and thus displaying the text (+1 for that) but unfortunately, this doesn't solve the issue with the resource binding ("{i18n>qty}") not working. Mar 27, 2018 at 9:19
0

At the point of opening the Dialog, it doesn't know the i18n model. You need to provide the model to the dialog by calling dialog.setModel(this.getModel('i18n'), 'i18n') before opening the dialog.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.