Show TOC

Binding Texts to a Resource BundleLocate this document in the navigation structure

To bind texts of a control in JSON views to a language-dependent resource bundle, define the resource bundle by a name (resourceBundleName property) or a URL (resourceBundleUrl property) and assign an alias (resourceBundleAlias property) for the bundle in the view definition.

Context

The ResourceModel required for binding these texts is created during view instantiation. The model is set as secondary model with the given alias to the view instance. If you want to bind other properties to another model, you have to create the model on your own in the corresponding controller or HTML page and attach it to the view with another alias. The binding itself behaves in the same way as every SAPUI5 data binding and as described above.

Procedure

  1. Define the following resource bundle content: MY_TEXT=Hello World
  2. To bind this resource bundle content, insert the following code depending on the view type:
    • For a JSON view, insert the following code:
      {	"Type": "sap.ui.core.JSONView",
      	 "controllerName":"my.own.views.test",
       	"resourceBundleName":"myBundle",
       	"resourceBundleAlias":"i18n",
       	"content": [{
          		"Type":"sap.ui.commons.Panel",
          		"id":"myPanel",
          		"content":[{
             			"Type":"sap.ui.commons.Button",
             			"id":"Button1",
             			"text":"{i18n>MY_TEXT}",
             			"press": "doIt"
          		}]
       	}]
      }
    • For a XML view, insert the following code:
      <core:View resourceBundleName="myBundle"
                 resourceBundleAlias="i18n" 
                 controllerName="sap.hcm.Address" xmlns="sap.ui.commons" xmlns:core="sap.ui.core"
                 xmlns:html="http://www.w3.org/1999/xhtml">
         <Panel>
            <Button text="{i18n>MY_TEXT}"/>
         </Panel>
      <core:View>