Search code examples
sapui5

How to use SAPUI5 i18n in controller?


Below is my scenario:

Output(sample)

Visit type: court
Purpose :
(or) if

Visit type: Site Visit (Factory)
Factory Name:

(*this is the split app, Master list contains two different text values "court" & "Site Visit (Factory)" based on the list user. *Now if the list contains the value "court" the label should change to purpose and if the list contains the value "Site Visit (Factory)" the label should change to Factory Name)

Kindly help me in it.

View

<Label id="idVisitType" text="{i18n>perdmm}" design="Bold" />
            <Text id="perdm_id" class="secondtable"></Text>

Controller

sap.ui.getCore().byId("detail_form_id--idsitevisit--visittypee").setText(oData.VisitType);
if (oData.VisitType == "Site Visit (Factory)") {
    sap.ui.getCore().byId("detail_form_id--idsitevisit--idVisitType").setText('{i18n>reasonfactory}');
} else {
    sap.ui.getCore().byId("detail_form_id--idsitevisit--idVisitType").setText('{i18n>perdmm}');
}

based on the above code the output is getting like this,

Output

Thanks in advance


Solution

  • Try this code:

    var sPerdmm = this.getView().getModel("i18n").getResourceBundle().getText(">perdmm");