2014-09-03 44 views
6

我有一個按鈕(創建應用程序),如果我點擊一個按鈕將出現一個零碎的對話框。這裏能夠顯示零碎的對話框。但是內部化(i18n)沒有出現在字段中。 (對於xml文件能夠證明i18nfragment.xml文件無法顯示i18n /)本地化(i18n)在sapui5 for fragment.xml文件沒有出現

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> 

回答

3

您應該也爲對話框片段設置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(); 
} 
12

您可以使用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(); 
} 

詳情請參閱my answer爲 'What is the usage of "dependents" aggregation in SAPUI5?'。

1

它通常是最簡單的方法。對於ResourceModel只是設置全局:

sap.ui.getCore().setModel(i18nModel, "i18n");

現在你可以在你的應用程序來自世界各地的引用,而且綁定到它像你這樣,不需要以後再設置它的視圖 - 甚至控制 - 水平。

+0

當您在Fiori Launchpad中工作時,不應該這樣做,因爲它與其他應用程序衝突。 – hirse 2016-05-10 13:36:02

1

我有同樣的問題,所以在組件中設置模型全局和本地。它工作正常。

sap.ui.getCore().setModel(i18nModel, "i18n"); 
this.setModel(i18nModel, "i18n");