Skip to content

Commit

Permalink
[INTERNAL] Create ResourceBundle asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
flovogt committed Oct 17, 2024
1 parent 38ca133 commit b10e12a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 380 deletions.
47 changes: 23 additions & 24 deletions webapp/controller/App.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/Filter",
"sap/ui/model/FilterOperator",
"sap/ui/model/json/JSONModel"
], (Device, Controller, Filter, FilterOperator, JSONModel) => {
"sap/ui/model/json/JSONModel",
"sap/base/strings/formatMessage"
], (Device, Controller, Filter, FilterOperator, JSONModel, formatMessage) => {
"use strict";

return Controller.extend("sap.ui.demo.todo.controller.App", {
Expand All @@ -14,8 +15,7 @@ sap.ui.define([
this.aTabFilters = [];

this.getView().setModel(new JSONModel({
isMobile: Device.browser.mobile,
filterText: undefined
isMobile: Device.browser.mobile
}), "view");
},

Expand Down Expand Up @@ -104,7 +104,7 @@ sap.ui.define([
break;
case "all":
default:
// Don't use any filter
// Don't use any filter
}

this._applyListFilters();
Expand All @@ -116,30 +116,29 @@ sap.ui.define([

oBinding.filter(this.aSearchFilters.concat(this.aTabFilters), "todos");

let sI18nKey;
if (this.sFilterKey && this.sFilterKey !== "all") {
if (this.sFilterKey === "active") {
sI18nKey = "ACTIVE_ITEMS";
} else {
// completed items: sFilterKey = "completed"
sI18nKey = "COMPLETED_ITEMS";
}
if (this.sSearchQuery) {
sI18nKey += "_CONTAINING";
}
} else if (this.sSearchQuery) {
sI18nKey = "ITEMS_CONTAINING";
}
const sI18nKey = this.getI18NKey(this.sFilterKey, this.sSearchQuery);

let sFilterText;
this.byId("filterToolbar").setVisible(!!sI18nKey);
if (sI18nKey) {
const oResourceBundle = this.getView().getModel("i18n").getResourceBundle();
sFilterText = oResourceBundle.getText(sI18nKey, [this.sSearchQuery]);
this.byId("filterLabel").bindProperty("text", {
path: sI18nKey,
model: "i18n",
formatter: (textWithPlaceholder) => {
return formatMessage(textWithPlaceholder, [this.sSearchQuery]);
}
});
}

this.getView().getModel("view").setProperty("/filterText", sFilterText);
},

getI18NKey(sFilterKey, sSearchQuery) {
if (!sFilterKey || sFilterKey === "all") {
return sSearchQuery ? "ITEMS_CONTAINING" : undefined;
} else if (sFilterKey === "active") {
return "ACTIVE_ITEMS" + (sSearchQuery ? "_CONTAINING" : "");
} else {
return "COMPLETED_ITEMS" + (sSearchQuery ? "_CONTAINING" : "");
}
}
});

});
3 changes: 2 additions & 1 deletion webapp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "sap.ui.demo.todo.i18n.i18n"
"bundleName": "sap.ui.demo.todo.i18n.i18n",
"async": true
}
},
"": {
Expand Down
Loading

0 comments on commit b10e12a

Please sign in to comment.