2015-04-14 49 views
1

我有一个代码,用于检查服务器的响应,并根据收到的信息显示消息框。我有两种语言的这些消息(用户在登录时选择一种语言)。 这里是例子:i18n型号无法正常工作

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

这里是国际化模型声明(这是以前我用的模型,当然申报):

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”。

它工作得很好,我无法弄清楚发生了什么。

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

谢谢。

+0

你有没有idnotnine = .properties文件中的一些文本? –

+0

@jumpifzero当然,我确实。此外,如果我把''{i18nResourceModel> idnotnine}“'作为'title'的文本,我确实看到了这个消息。 – keshet

回答

3

数据绑定通常不适用于像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 
     } 
); 

此外,您可以看看如何使用资源包here最新的指南。

+0

我尝试了一些你在你的代码中做的事情,它确实有效。我的沮丧来自数据绑定DID的工作,现在它只在消息框的主体中不起作用。所有的控制标签和消息框标题都很好。 – keshet

+0

我明白了你的观点。其实我真的很想知道为什么它以前适合你。根据SAPUI5/OpenUI5的文档,数据绑定语法仅适用于从ManagedObject继承的控件。 –