0

I am working on an SAPUI5 application. We are using i18n localization concept wherein we have declared properties for all static texts on our application and assigned values to them that can be used for example like this:

var oButton = new sap.ui.commons.Button();
oButton.setText(oBundle.getText("LOGIN_BUTTON_NAME"));

Now I have a requirement where certain label texts have to be updated dynamically based on user settings. And these texts are defined in the i18n bundle. So I am looking for something like:

//Update i18n bundle
oBundle.setText("USERNAME_LABEL", "Username");
//Use updated value
oLabel.setText(oBundle.getText("USERNAME_LABEL"));

But I couldn't find a setText() method anywhere.

Any help will be deeply acknowledged.

4

1 回答 1

1

抱歉我迟到了:D

您不应该这样做,因为 i18n 资源是静态文本。

最好的方法是如果你定义一个额外的 JSONModel 并加载你想要从你的包中更改的数据。

如果你有这样的标签:

<Label text="{/USERNAME_LABEL}" />

您可以使用以下代码:

var oModel = new JSONModel({
    USERNAME_LABEL: oBundle.getText("USERNAME_LABEL")
});

oLabel.setModel(oModel);

现在每次你想更新文本时,你可以这样做:

var oData = oModel.getData();
oData.USERNAME_LABEL = "bla...";
oModel.refresh();

并且视图将自动更新。

于 2015-12-29T12:14:28.990 回答