【问题标题】:i18n model doesn't work properlyi18n 型号无法正常工作
【发布时间】:2015-04-14 15:57:35
【问题描述】:

我有一个代码可以检查来自服务器的响应并根据收到的信息显示消息框。我有 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”。

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

什么可能导致此问题,我该如何解决?

谢谢。

【问题讨论】:

  • .properties 文件中是否有 idnotnine=一些文本?
  • @jumpifzero 当然,我愿意。此外,如果我将"{i18nResourceModel>idnotnine}" 作为title 的文本,我确实看到了正确的消息。

标签: javascript internationalization sapui5


【解决方案1】:

数据绑定通常不适用于像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 的最新指南。

【讨论】:

  • 我尝试了您在代码中所做的事情,它确实有效。我的沮丧来自一个事实,即数据绑定确实有效,而现在它仅在消息框的正文中不起作用。所有控件标签和消息框标题都很好。
  • 我明白你的意思。其实我真的很想知道为什么它以前对你有用。根据 SAPUI5/OpenUI5 的文档,数据绑定语法仅适用于从 ManagedObject 继承的控件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-01
相关资源
最近更新 更多