i18n模型无法正常工作 [英] i18n model doesn't work properly
问题描述
我有一个代码,用于检查服务器的响应并根据收到的信息显示消息框.我有2种语言的这些消息(用户在登录时选择一种语言). 这是示例:
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}"}
);
}
这是i18n模型声明(当然是在使用模型之前声明的):
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");
我有2个.properties
文件:i18n.properties
(英语)和i18n_iw.properties
(希伯来语).
I have 2 .properties
files: i18n.properties
(english) and i18n_iw.properties
(hebrew).
奇怪的是,消息框的title
正确翻译了,但是我看到的不是消息本身,而是文本:"i18nResourceModel> idnotnine".
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?
谢谢.
推荐答案
数据绑定通常在sap.m.MessageBox.alert()
之类的函数调用中不起作用.您必须手动获取文本,例如:
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
}
);
此外,您还可以查看有关如何使用ResourceBundle的最新指南
Additionally you can have a look at the latest guide on how to use the ResourceBundle here.
这篇关于i18n模型无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!