aru*_*unk 6 localization sapui5
我有一个按钮(创建应用程序),如果我点击一个按钮,将出现一个碎片对话框.这里能够显示碎片化的对话框.但内部化(i18n)没有出现在字段中.(对于xml能够显示i18n但fragment.xml文件无法显示的文件i18n/)
component.js:
createContent : function() {
// create root view
var oView = sap.ui.view({
id : "app",
viewName : "sap.gss.program.view.App",
type : "JS",
viewData : { component : this }
});
var i18nModel = new sap.ui.model.resource.ResourceModel({
bundleUrl : "i18n/appTexts_fr.properties"
});
oView.setModel(i18nModel, "i18n");
return oView;
}
Run Code Online (Sandbox Code Playgroud)
Controller.js:
createApplication: function (oEvent) {
if (!this.oDialogFragment) {
this.oDialogFragment = sap.ui.xmlfragment("sap.gss.program.view.myFragment",
this);
}
this.oDialogFragment.open();
}
Run Code Online (Sandbox Code Playgroud)
fragment.xml:
<core:FragmentDefinition
xmlns="sap.m"
xmlns:core="sap.ui.core"
xmlns:app="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1">
<Dialog
title="{i18n>Title}"
class="sapUiPopupWithPadding" >
<HBox>
<Text text="{i18n>Description_TEXT}" > </Text>
</HBox>
<beginButton>
<Button text="{i18n>Ok}" press="DialogButton" />
</beginButton>
<endButton>
<Button text="{i18n>Cancel}" press="CloseButton" />
</endButton>
</Dialog>
</core:FragmentDefinition>
Run Code Online (Sandbox Code Playgroud)
qma*_*cro 15
您可以使用dependents聚合,将对话框连接到视图; 您不需要明确设置任何模型.
所以在你的情况下你会这样做:
createApplication: function (oEvent) {
if (!this.oDialogFragment) {
this.oDialogFragment = sap.ui.xmlfragment("sap.gss.program.view.myFragment", this);
}
this.getView().addDependent(oDialogFragment); // <--
this.oDialogFragment.open();
}
Run Code Online (Sandbox Code Playgroud)
请参阅我对SAPUI5中"依赖"聚合的用法的回答?' 更多细节.
您还应该为对话框片段设置 i18n 资源模型。
createApplication: function(oEvent) {
if (!this.oDialogFragment) {
this.oDialogFragment = sap.ui.xmlfragment("sap.gss.program.view.myFragment", this);
var i18nModel = new sap.ui.model.resource.ResourceModel({
bundleUrl : "i18n/appTexts_fr.properties"
});
this.oDialogFragment.setModel(i18nModel, "i18n");
}
this.oDialogFragment.open();
}
Run Code Online (Sandbox Code Playgroud)