I have a button (create Application) if i click on a button a fragmented dialog will be appearing . here am able to show fragmented dialog .but internalization(i18n) is not appearing for the fields. (For xml
files able to show i18n
but for fragment.xml
file not able to show 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;
}
Controller.js
:
createApplication: function (oEvent) {
if (!this.oDialogFragment) {
this.oDialogFragment = sap.ui.xmlfragment("sap.gss.program.view.myFragment",
this);
}
this.oDialogFragment.open();
}
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>
You can use the dependents
aggregation, to connect up the dialog to the view; you don't need to set any models explicitly.
So in your case you would do this:
createApplication: function (oEvent) {
if (!this.oDialogFragment) {
this.oDialogFragment = sap.ui.xmlfragment("sap.gss.program.view.myFragment", this);
}
this.getView().addDependent(oDialogFragment); // <--
this.oDialogFragment.open();
}
See my answer to 'What is the usage of "dependents" aggregation in SAPUI5?' for more details.
you should set the i18n resource model for the dialog fragment as well.
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();
}
Its often the easiest way esp. for a ResourceModel
to just set it globally:
sap.ui.getCore().setModel(i18nModel, "i18n");
Now you can reference it from everywhere in your application and bind to it like you did, no need to ever set it again on view- or even control-level.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With