In this blog I’ll share with you a helpful strategy I came up with along my Fiori development jouney – reutilizing standard i18n texts.
Introduction
Over the course of a Fiori app development, I was bored of writing some of the most commonly-used labels in the i18n files (like Dialog labels – e.g. “Close”, “Confirm”), over and over, app after app.
I thought to myself “How can I overcome this?”.
Then I decided to experiment to include an i18n file from the UI5 libraries in the app manifest and try it out.
Guess what – it worked 😊
How-to
Basically, all you need to is the following:
- In the app manifest (manifest.json), manually configure a new i18n model (similar to the default ones), mapped to the URL of a i18n file from some UI5 library:
"models": { "i18n": { (...) }, "": { (...) }, "i18n_sap_m": { "type": "sap.ui.model.resource.ResourceModel", "settings": { "bundleUrl": "/resources/sap/m/messagebundle.properties" } } },
- As a result, it will load the configured (standard) i18n file (allowing you to freely use its texts):
- Example of bundle URLs:
- sap.m (/resources/sap/m/messagebundle.properties or https://ui5.sap.com/resources/sap/m/messagebundle.properties)
- sap.f (/resources/sap/f/messagebundle.properties or https://ui5.sap.com/resources/sap/f/messagebundle.properties)
- sap.ui.core (/resources/sap/ui/core/messagebundle.properties or https://ui5.sap.com/resources/sap/ui/core/messagebundle.properties)
- Utilize the standard i18n model as you would use your default i18n model – for example:
Note: this does work in any type of UI5 development (UI5 freestyle app, SAP Fiori Elements app, SAP Fiori Launchpad plugin, etc).
Advantages
- Cleaner/Smaller custom i18n files
- Less translation effort (since you’ll be reutilizing standard texts, all their translations will be also reutilized with no effort)
Disadvantages
None 😊
Conclusion
To sum up, by referencing SAP i18n resource bundles, we end up reutilizing existing i18n texts in the UI5 framework, reducing and leading to cleaner Fiori solutions.
Any questions/comments/suggestions?
Feel free to leave them down below.
For more UI5-related resources, feel free to:
– Follow the UI5 topic > https://community.sap.com/topics/ui5
– Post/answer UI5-related questions > https://answers.sap.com/tags/500983881501772639608291559920477
– Read other UI5-related posts > https://blogs.sap.com/tags/500983881501772639608291559920477