How to Use Internalization i18n in a Controller in SAPUI5?

后端 未结 2 1611
一生所求
一生所求 2021-01-25 08:25

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         


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-25 09:14

    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")'.

提交回复
热议问题