Model implementation for resource bundles.
This model is not prepared to be inherited from.
This model allows to bind control properties against translatable texts. Its data is taken from a module:sap/base/i18n/ResourceBundle and it only supports property bindings.
In contrast to most other models, binding paths for a ResourceModel
must not start with a slash; they are absolute by default, and there's no further structure. Each key in the underlying resource bundle is a valid binding path.
In extensibility scenarios, the texts of the resource bundle can be enhanced with additional resource bundles. These additional bundles can define new texts for existing keys, texts for new keys, or both. When texts for existing keys are replaced, the latest enhancement wins.
This model supports the binding modes OneWay
and OneTime
, but not TwoWay
. When the recommended asynchronous loading of the bundle is used, binding mode OneTime
can't be used.
Constructor for a new ResourceModel.
The ResourceModel can be created using configuration objects instead of ResourceBundle
instances. This is the recommended way and enables:
The ResourceModel can be created in a programmatic manner which means that ResourceBundle
instances are used instead of configurations. Existing ResourceBundles can either be used in the bundle
parameter or in the enhanceWith
array. Runtime errors are thrown when ResourceBundle
instances are used with terminologies
. Also when using ResourceModel#enhance
with terminologies
.
new sap.ui.model.resource.ResourceModel(oData)
Param | Type | Default Value | Description |
---|---|---|---|
oData | object | Parameters used to initialize the |
|
activeTerminologies? | string[] | The list of active terminologies, e.g. |
|
async? | boolean | false | Whether the language bundle should be loaded asynchronously |
bundle? | module:sap/base/i18n/ResourceBundle | A resource bundle instance; when given, this bundle is used instead of creating a bundle from the provided |
|
bundleLocale? | string | A locale in "BCP-47 language tag" notation specifying the locale in which to load the bundle; when not given, the current session locale of UI5 is used (recommended) |
|
bundleName? | string | UI5 module name in dot notation referring to the base ".properties" file; this name is resolved to a path just as for normal UI5 modules, to which ".properties" is then appended (e.g. a name like "myapp.i18n.myBundle" can be given); relative module names are not supported |
|
bundleUrl? | string | URL pointing to the base ".properties" file of a bundle (".properties" file without any locale information, e.g. "../../i18n/mybundle.properties"); relative URLs are evaluated relative to the document.baseURI |
|
defaultBindingMode? | sap.ui.model.BindingMode | OneWay | The default binding mode to use; it can be |
enhanceWith? | module:sap/base/i18n/ResourceBundle[] module:sap/base/i18n/ResourceBundle.Configuration[] | A list of resource bundles or resource bundle configurations that enhance the texts from the main bundle; intended for extensibility scenarios; see also the class documentation. ResourceBundles use the ResourceModel's enhance mechanism and |
|
fallbackLocale? | string | "en" | A fallback locale to be used after all locales derived from To prevent a generic fallback, use the empty string ( |
supportedLocales? | string[] | List of supported locales (aka 'language tags') to restrict the fallback chain. Each entry in the array can either be a BCP47 language tag or a JDK compatible locale string (e.g. "en-GB", "en_GB" or "en"). An empty string ( Note: The given language tags can use modern or legacy ISO639 language codes. Whatever language code is used in the list of supported locales will also be used when requesting a file from the server. If the |
|
terminologies? | Object<string,module:sap/base/i18n/ResourceBundle.TerminologyConfiguration> | An object, mapping a terminology identifier (e.g. "oil") to a |
Method | Description |
---|---|
bindProperty |
Gets a property binding for the given path in the resource model. Only |
enhance |
Enhances the resource model with a custom resource bundle. The custom bundle can define new texts for keys existing in the main bundle, texts for new keys, or both. A resource model can be enhanced with multiple resource bundles by calling this method multiple times. Each call appends to the list of enhancements, but no bundle can be removed from the list. When looking up a text for a key, the enhancements are processed in reverse order. Texts from the last added resource bundle are preferred over texts from previously added bundles or texts from the main bundle. |
sap.ui.model.resource.ResourceModel.extend |
Creates a new subclass of class sap.ui.model.resource.ResourceModel with name
|
sap.ui.model.resource.ResourceModel.getMetadata |
Returns a metadata object for class sap.ui.model.resource.ResourceModel. |
getProperty |
Returns the value for the property with the given path. |
getResourceBundle |
Gets the resource bundle of this model. |
sap.ui.model.resource.ResourceModel.loadResourceBundle |
Returns the resource bundle or a promise resolving with the resource bundle. |
Gets a property binding for the given path in the resource model. Only sPath
from sap.ui.model.Model#bindProperty is supported; other parameters are ignored.
Param | Type | DefaultValue | Description |
---|---|---|---|
sPath | string |
The path pointing to the property that should be bound; in contrast to most other models, the binding path for a |
Enhances the resource model with a custom resource bundle.
The custom bundle can define new texts for keys existing in the main bundle, texts for new keys, or both. A resource model can be enhanced with multiple resource bundles by calling this method multiple times. Each call appends to the list of enhancements, but no bundle can be removed from the list.
When looking up a text for a key, the enhancements are processed in reverse order. Texts from the last added resource bundle are preferred over texts from previously added bundles or texts from the main bundle.
Param | Type | DefaultValue | Description |
---|---|---|---|
oData | module:sap/base/i18n/ResourceBundle object |
Either an already loaded bundle instance, or a configuration object with parameters to load a new resource bundle. When a configuration object is given, at least one of |
|
bundleLocale | string |
A locale in "BCP-47 language tag" notation specifying the locale in which to load the bundle; when not given, the current session locale of UI5 is used (recommended) |
|
bundleName | string |
UI5 module name in dot notation, referring to the base ".properties" file; this name is resolved to a path like the paths of normal UI5 modules, and ".properties" is then appended (e.g. a name like "myapp.i18n.myBundle" can be given); relative module names are not supported |
|
bundleUrl | string |
URL pointing to the base ".properties" file of a bundle (".properties" file without any locale information, e.g. "../../i18n/mybundle.properties"); relative URLs are evaluated relative to the document.baseURI |
Creates a new subclass of class sap.ui.model.resource.ResourceModel with name sClassName
and enriches it with the information contained in oClassInfo
.
oClassInfo
might contain the same kind of information as described in sap.ui.model.Model.extend.
Param | Type | DefaultValue | Description |
---|---|---|---|
sClassName | string |
Name of the class being created |
|
oClassInfo | object |
Object literal with information about the class |
|
FNMetaImpl | function |
Constructor function for the metadata object; if not given, it defaults to the metadata implementation used by this class |
Returns a metadata object for class sap.ui.model.resource.ResourceModel.
Returns the value for the property with the given path.
Param | Type | DefaultValue | Description |
---|---|---|---|
sPath | string |
The path to the property |
Returns the resource bundle or a promise resolving with the resource bundle.
Param | Type | DefaultValue | Description |
---|---|---|---|
oData | object |
Parameters used to load the resource bundle; see constructor of the sap.ui.model.resource.ResourceModel |
|
activeTerminologies | string[] |
The list of active terminologies, e.g. |
|
bundleLocale | string |
A locale in "BCP-47 language tag" notation specifying the locale in which to load the bundle; when not given, the current session locale of UI5 is used (recommended) |
|
bundleName | string |
UI5 module name in dot notation referring to the base ".properties" file |
|
bundleUrl | string |
URL pointing to the base ".properties" file of a bundle |
|
enhanceWith | module:sap/base/i18n/ResourceBundle[] module:sap/base/i18n/ResourceBundle.Configuration[] |
A list of resource bundles or resource bundle configurations that enhance the texts from the main bundle; intended for extensibility scenarios; see also the class documentation. ResourceBundles use the ResourceModel's enhance mechanism and ResourceBundle.Configurations get passed to the underlying ResourceBundle (see module:sap/base/i18n/ResourceBundle.create). Supported since 1.77.0. |
|
fallbackLocale | string | "en" |
A fallback locale to be used after all locales derived from To prevent a generic fallback, use the empty string ( |
supportedLocales | string[] |
List of supported locales (aka 'language tags') to restrict the fallback chain. Each entry in the array can either be a BCP47 language tag or a JDK compatible locale string (e.g. "en-GB", "en_GB" or "en"). An empty string ( |
|
terminologies | Object<string,module:sap/base/i18n/ResourceBundle.TerminologyConfiguration> |
An object mapping a terminology identifier (e.g. "oil") to a |
|
bAsync | boolean |
Whether the resource bundle should be loaded asynchronously |