How to Use Internalization i18n in a Controller in SAPUI5?

寵の児 提交于 2019-12-04 05:30:58

问题


Could anyone please explain how it's possible to use a i18n text in a setValueStateText method in a controller?

oTP.setValueStateText("{i18n>co_Maximal_60_h}");

The error msg in the dialog shows only "{i18n>co_Maximal_60_h}" and not the real text.


回答1:


You cannot set the binding string via setter method. Here you have 2 options:

  1. set the binding right in the view (use the same string but in XML)
  2. utilize the ResourceBundle:

    var oResourceBundle = this.getOwnerComponent().getModel("i18n").getResourceBundle();
    
    var sTxt = oResourceBundle.getText("co_Maximal_60_h");
    
    oTP.setValueStateText(sTxt);
    

I'd recommend to add a reusable method to your BaseController with a name "i18n", so whenever you need it, call 'this.i18n("i18n_key")'.




回答2:


the resource bundle is in the following way accessible in a controller:

...
  var oResourceBundle = this.getView().getModel("i18n").getResourceBundle();
  oTP.setValueStateText(oResourceBundle.getText("co_Maximal_60_h"));
...


来源:https://stackoverflow.com/questions/45761026/how-to-use-internalization-i18n-in-a-controller-in-sapui5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!