Search code examples
sapui5

Get i18n text for specific locale


I have two models of i18n:

  • i18n_en.properties for English
  • i18n_ar.properties for Arabic

My goal here is to get the corresponding text for English only despite the detected language.

The following function gets the text based on the automatic language detection.

fGetText: function(sText) {
  var oBundle = this.getView().getModel("i18n").getResourceBundle();
  return oBundle.getText(sText);
},

Is there a way to retrieve text for specific language?


Solution

  • You can use ResourceBundle.create method for creating new one with giving locale param.

    ResourceBundle.create({
      url : "i18n/i18n.properties",
      locale : "en",
      async: true,
    })
    

    Documentation of ResouceBundle here.