我创建了我的.properties文件(it,en,fr),并设置了i18n模型
var oI18nModel = new sap.ui.model.resource.ResourceModel({
bundleUrl: "i18n/i18n.properties"
});
sap.ui.getCore().setModel(oI18nModel, "i18n");
this.setModel(oI18nModel, "i18n");我的应用程序用意大利语正确启动。现在我有了一个按钮,可以切换到en语言。这是代码:
var bundleLocale=sap.ui.getCore().getModel("i18n").getProperty("/bundleLocale/");
bundleLocale="en";
sap.ui.getCore().getModel("i18n").refresh(true);但观点没有改变..。
为什么?
在开始时,i18n模型包含:
bundleUrl= "i18n/i18n.properties"在此之后,我执行以下代码:
i18nModel = new sap.ui.model.resource.ResourceModel({
bundleUrl : "i18n/i18n.properties",
bundleLocale : "fr"
});
sap.ui.getCore().setModel(i18nModel, "i18n");模型现在包含
bundleUrl= "i18n/i18n.properties"
bundleLocale="fr"相反,如果我使用以下代码:
sap.ui.getCore().getConfiguration().setLanguage("fr")i18n模型不变
在这两种情况下,我的观点都没有改变
发布于 2015-02-11 10:17:26
我已经解决了我的问题!在我的Component.js中,在init函数中,我写了:
var oI18nModel = new sap.ui.model.resource.ResourceModel({
bundleUrl: "i18n/i18n.properties"
});
sap.ui.getCore().setModel(oI18nModel, "i18n");
this.setModel(oI18nModel, "i18n");在createContent函数中,我写了:
// create root view
var oView = sap.ui.view({
id: "app",
viewName: "stg.view.App",
type: "JS",
viewData: {
component: this
}
});当我想改变我所写的语言时:
var i18nModel = new sap.ui.model.resource.ResourceModel({
bundleUrl : "i18n/i18n.properties",
bundleLocale : sBundleLocale
});
sap.ui.getCore().setModel(i18nModel , "i18n");但在这种模式下,我没有看到任何变化。现在我写
var oApp = sap.ui.getCore().byId("app");
oApp.getViewData().component.setModel(i18nModel, "i18n");很管用!!
发布于 2015-02-10 17:12:31
在您的代码中,您从资源包(即翻译之一)获得一个属性,而不是实际的区域设置--而且,您正在设置一个变量bundleLocale,但您从未使用该变量.
设置应用程序语言的正确方法是使用sap.ui.core.Configuration的setLanguage()方法(参见https://sapui5.netweaver.ondemand.com/sdk/docs/api/symbols/sap.ui.core.Configuration.html#setLanguage)。
作为另一种选择,向地区提供您的资源模型:
setLanguage : function(sLanguage) {
i18nModel = new sap.ui.model.resource.ResourceModel({
bundleUrl : "i18n/i18n.properties",
bundleLocale : sLanguage
});
sap.ui.getCore().setModel(i18nModel, "i18n");
}编辑:参见此工作示例http://plnkr.co/edit/pj6Ze1D60lrXQ47peowT?p=preview
使用视图中的开关在德语和英语UI语言之间切换
https://stackoverflow.com/questions/28436621
复制相似问题