i18n 模型不能正常工作

i18n model doesn't work properly

我有一个代码可以检查来自服务器的响应并根据收到的信息显示消息框。我有 2 种语言的这些消息(用户在登录期间选择一种语言)。 这是示例:

if(sResponse == 'IDfail'){
    sap.m.MessageBox.alert
    ("{i18nResourceModel>idnotnine}", 
        {icon: sap.m.MessageBox.Icon.ERROR,
        title: "{i18nResourceModel>error}"}
    );
}

这里是i18n模型声明(当然是在我使用模型之前声明的):

var oResourceModel = new sap.ui.model.resource.ResourceModel
    ({bundleUrl: "i18n/i18n.properties", bundleLocale: "en"});
sap.ui.getCore().setModel(oResourceModel, "i18nResourceModel");

我有 2 个 .properties 文件:i18n.properties(英语)和 i18n_iw.properties(希伯来语)。

奇怪的是,消息框的 title 翻译正确,但我看到的不是消息本身,而是文本:"i18nResourceModel>idnotnine".

之前它运行良好,但我不知道发生了什么。

可能是什么原因导致了这个问题,我该如何解决?

谢谢。

数据绑定在像 sap.m.MessageBox.alert() 这样的函数调用中通常不起作用。您必须手动获取文本,例如:

var resourceModel = sap.ui.getCore().getModel("i18nResourceModel");
var alertText = resourceModel.getProperty("idnotnine");
var alertTitle = resourceModel.getProperty("error");

sap.m.MessageBox.alert(alertText, {
          icon: sap.m.MessageBox.Icon.ERROR,
          title: alertTitle 
      }
);

此外,您还可以查看有关如何使用 ResourceBundle 的最新指南 here