i18n model doesn't work properly

我是研究僧i 提交于 2019-12-24 16:30:45

问题


I have a code that checks a response from a server and shows message box according to the information received. I have these messages in 2 languages (user selects a language during login). Here is example:

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

Here is i18n model declaration (it is declared before I use the model, of course):

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

I have 2 .properties files: i18n.properties (english) and i18n_iw.properties (hebrew).

The strange thing is that the title of the message box is translated correctly, but instead of the message itself I see text: "i18nResourceModel>idnotnine".

It worked fine before and I can't figure out what happened.

What may be causing this issue and how do I fix it?

Thank you.


回答1:


Databinding is usually not working in a function call like sap.m.MessageBox.alert(). You have to get the text manually like:

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 
      }
);

Additionally you can have a look at the latest guide on how to use the ResourceBundle here.



来源:https://stackoverflow.com/questions/29632022/i18n-model-doesnt-work-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!