2

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

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

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

Mike
  • 14,010
  • 29
  • 101
  • 161
user2405095
  • 113
  • 4
  • 16

2 Answers2

5

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

const oResourceBundle = this.getView().getModel("i18n").getResourceBundle();

oTP.setValueStateText(oResourceBundle.getText("co_Maximal_60_h"));
Mike
  • 14,010
  • 29
  • 101
  • 161
n01dea
  • 1,532
  • 1
  • 16
  • 33
5

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

  1. to set the binding right in the view (use the same string but in XML)
  2. to utilize the ResourceBundle:
const oResourceBundle = this.getOwnerComponent().getModel("i18n").getResourceBundle();
    
const 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").

Mike
  • 14,010
  • 29
  • 101
  • 161
Andrew Naumovich
  • 1,441
  • 1
  • 12
  • 15