i18n model is not yet loaded or available during the early controller lifecycle hooks.onInitonInit: function () {
// This fails because the model is not ready yet
this._oBundle = this.getView().getModel("i18n").getResourceBundle();
}Console Error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'getText')
2. Accessing it inside onBeforeRendering:
onBeforeRendering: function () {
this._oBundle = this.getView().getModel("i18n").getResourceBundle();
},var sTitle = this._oBundle.getText("shellBarTitle", [sTime, sDate]);
this.byId("_IDGenShellBar").setTitle(sTitle);It did not work. The title is blank
I am sure this is a common scenario, but many older SAP Community solutions I found rely on deprecated synchronous methods
i18n resource bundle as soon as it becomes available in the lifecycle?Request clarification before answering.
Hello @deiamolina
The i18n model is likely not available when onInit() or onBeforeRendering() runs.
Use the model from the Component and wait for the ResourceBundle promise:
onInit: async function () {
const oBundle = await this.getOwnerComponent()
.getModel("i18n")
.getResourceBundle();
const sTitle = oBundle.getText("shellBarTitle", [sTime, sDate]);
this.byId("_IDGenShellBar").setTitle(sTitle);
}
Or:
this.getOwnerComponent()
.getModel("i18n")
.getResourceBundle()
.then((oBundle) => {
this.byId("_IDGenShellBar")
.setTitle(oBundle.getText("shellBarTitle", [sTime, sDate]));
});
Access the i18n model through getOwnerComponent().getModel("i18n") instead of this.getView().getModel("i18n"), and handle getResourceBundle() asynchronously in newer SAPUI5 versions.
Thanks,
Sravan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 6 | |
| 5 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.