cancel
Showing results for 
Search instead for 
Did you mean: 

getText method of ResourceModel

11-28-2018 5:26 AM
SAP Managed Tags
Subscribe

I see that the ResourceBundle is deprecated and is replaced by module:sap/base/i18n/ResourceBundle. When I use the latter one, I am not able to access the getText method to retrieve text from my i18n.properties file. PFA for the logs.

TIA

Accepted Solutions (1)

Accepted Solutions (1)

boghyon
Product and Topic Expert
Product and Topic Expert

The module "sap/base/i18n/ResourceBundle" is available since 1.58. According to your screenshot, your application is running on 1.28, which is outdated and already out of maintenance.

Since it's a demo application, you can bootstrap the application with the latest stable version like this:

<script id="sap-ui-bootstrap" src="https://ui5.sap.com/resources/sap-ui-core.js"
  data-sap-ui-libs="..."
  data-sap-ui-async="true"
  data-sap-ui-theme="sap_belize"
  data-sap-ui-compatversion="edge"
  data-sap-ui-xx-waitfortheme="true"
></script>

The current stable version is at 1.58.x. With that, the module "sap/base/i18n/ResourceBundle" is available which you should define as one of the dependencies in the Controller:

sap.ui.define([
  // ...,
  "sap/base/i18n/ResourceBundle"
], function(/*...,*/ ResourceBundle) {
  "use strict";
  //...{
    ResourceBundle.create({
      url: sap.ui.require.toUrl("sap.ui.demo/i18n/i18n.properties"),
      async: true //<-- Please use always async. Default is false.
    }).then(function(bundle) {
      var message = bundle.getText("wishMeMsg", [sRecipient]);
      // ...
    }.bind(this));
  //}
});
Former Member
0 Likes

Thank you for the inputs!

Answers (1)

Answers (1)

jorge_cabanas
Participant
0 Likes

Hi Meghana,

I'm not sure about the deprecation that you talked...

Anyway, try better this:

onInit: function() {           

          this.oBundle = this.getOwnerComponent().getModel('i18n').getResourceBundle();

}

wishMeNow: function() {           

      this.oBundle.getText("myText")
}

Additionally, ensure that you have defined it in Manifest.json

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

Kind regards,
Jorge
Former Member
0 Likes

Thank you jorge_cabanas