In this part, let's research the control internationalization ( I call it i18n in this blog ) support.
There is some small modification needs to be done on the simple application.
The complete source code of html file:
Create a folder named "buttontutorial", and put two files into that folder:
The folder structure should be below:
-- | buttontutorial|
|- i18n.properties
|- i18n_zh.properties
| application.html
In the runtime, you will see two buttons below, with the two resource files downloaded via the Network tab.
This is for the button in the left, with text "吉瑞".
Put the mouse on the column "Initiator" for the first file "i18n_zh.properties", and through the callstack you can find the load of this file is just triggered by the line:
var oAppI18nModel1 = new sap.ui.model.resource.ResourceModel({
bundleName : "buttontutorial.i18n",
bundleLocale : oLocale
});
What does the returned object oAppl18nModel1 consist of?
1. A local information zh ( Correct, since my Chrome language setting is set to Chinese )
2. the value for key "BUTTON_LABEL". When you call function getText() of _oResourceBundle, it is just this value returned.
3. the default binding mode: OneTime
Still remember the Implementations for different binding mode: OneWay, TwoWay, OneTime introduced in part7 of this tutorial?
In SAP UI5 documentation, it is also mentioned that Resource model only supports OneTime binding mode:
This is for button with text "Jerry". As I have explicitly pass the locale "en" into constructor of ResourceModel, the 404 error for i18n_en.properties is expected since I don't create such file under "buttontutorial" folder.
However, why is the second i18n.properties loaded? Let's first have a look at the state of oAppI18nModel2. Please compare mProperties with the one in oAppI18nModel1. It is empty, so according to the logic in previous chapter, getText will fail to serve.
Fortunately, the UI5 framework has fallback mechanism to try the load the default file instead. See the comment below.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
36 | |
25 | |
16 | |
13 | |
7 | |
7 | |
6 | |
6 | |
6 | |
6 |