cancel
Showing results for 
Search instead for 
Did you mean: 

Resource Bundle not working in fragment

Former Member
0 Kudos

I am following the SAP's guidelines and updated the manifest.json with my resource bundle.

SAPUI5 SDK - Demo Kit

"models": {
 
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
 
"bundleName": "sap.ui.demo.wt.i18n.i18n"
}
 
}
}

This is not working in Fragment.


<core:FragmentDefinition xmlns:core="sap.ui.core" xmlns:commons="sap.ui.commons"

  xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"

  xmlns:html="http://www.w3.org/1999/xhtml"

  xmlns:form="sap.ui.layout.form"

  xmlns:l="sap.ui.layout" xmlns:sap.ui.core="sap.ui.core">

  <Dialog

        title="{i18n>titleFragTitle}" contentWidth="50%">

        <content>

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos

can u show me the code how you initialize the fragment?

Former Member
0 Kudos

In my controller, I have the fragment called

this._oPopover = sap.ui.xmlfragment("myapp.fragment.myfragment", this);

this._oPopover.openBy(evt.getSource());

SAP is asking to use manifest.json for calling the resource bundle i18n.properties. Should we continue with that option or we need to use Component.js

Also, I can get the translations from properties in the main View but in the fragment they are not loading.

junwu
Active Contributor
0 Kudos

this.getView().addDependent(this._oPopover);


try this

Former Member
0 Kudos

Hi Jun,

It worked !! Why should we add the above link....?? I have not got this issue earlier.

Former Member
0 Kudos

Hi Jun

when we use this for the fragement, the popover is very slow


I changed from responsive Popover to Dialog, but still Dialog is also very slow.. if I comment the below code, it works very fast.


this.getView().addDependent(this._oPopover);

0 Kudos

What do you mean with slow? Normally this should not affect speed. Add dependent adds the Dialog to the dependent aggregation of your view. Then it will get access to the models on the view and also be destroyed when the view gets destroyed.

  • Slow already first time or when opening again and again getting slower? --> maybe check if you instantiate multiple times
  • You can also try to set the model to the dialog/popover directly by calling this._oPopover.setModel(this.getView().getModel("i18n"), "i18n") and see if it then is faster again.

Answers (1)

Answers (1)

former_member185414
Active Contributor
0 Kudos

Hi Suhaas,

Manifest.json is the app descriptor file. Here we specify only the configurations and paths. To be able to use the resource model (and for that matter any other model also) you need to create it and associate the same with either component or view or fragment.

Sample is -

In component controller -

// set the i18n model

  this.setModel(models.createResourceModel(bundleName), "i18n");

in models.js file create a function as -

createResourceModel: function(sBundleName) {

  var oResourceModel = new ResourceModel({

  "bundleName": sBundleName

  });

  return oResourceModel;

  },

Then you can reference the same and it will work.

BR.

Former Member
0 Kudos

Hi Ankit

Iam not doing the above becuase, SAP says below and I am in SAPUI5 verison 1.32


Automatic model instantiation is only available as of SAPUI5 version 1.30. If you are using an older version, you can manually instantiate the resource bundle and other models of the app in the

init

method of the

Component.js

file as we did in Step 9: Component Configuration.

Also, when I try below code in my controller instead of Component.js , it did not work.