Reputation: 5018
I have a SAPUI5 app that tries to load some translation files based on user language but those languages are missing in the original library of SAP.
For example it tries to load a translation with fa
locale as following:
https://webidetestingXXXXXXX.dispatcher.hana.ondemand.com/webapp/resources/sap/m/messagebundle_fa.properties
As it can be seen it tries to read the translation from sap.m
namespace!
Now the question is, as I have access to English translation file of this recourse, how can I activate a call back mechanism that when a translation file is missing, it takes a look on my i18n folder and then if it couldn't find the file there, then load the default translation!?
For example I can download the English file and provide a translation for Persian language under webapp\i18n\sap\m\messagebundle_fa.properties
and when it's failed to find the file in original place then read it from my local folder!
Please note the actual address of my webapp\i18n
folder inside the WebIDE is something similar to https://webidetestingXXXX.dispatcher.hana.ondemand.com/~1595255696000~/webapp/i18n/
. That ~1595255696000~
refers to the current instance of run app. And as you see it is missing for the files that failed to load!
Upvotes: 2
Views: 1271
Reputation: 311
There's no specific redirect or callback mechanism for resource bundles in UI5.
The only workarounds that I can imagine, are either to use the paths mapping feature of the UI5 module loader to redirect requests for all language files of a library to your own, enriched copy (A) or to preload them and register them under the expected names in the loader (B).
Both variants have to be applied early, before UI5 tries to access any text from the libraries that you want to enrich.
Note: I did not fully test these workarounds (they might contain typos or the mappings / resources might have to be adapted), and, and that's the bad part, they only work for UI5 versions < 1.78. Starting with 1.78, UI5 knows what *.properties files exist per library and does not request any other file.
sap.ui.loader.config({
paths: {
"sap/m/messagebundle.properties": "my/enriched/copy/messagebundle.properties"
}
});
// somehow load the 'fa' texts for sap.m (ideally async)
var sapmtext = ...;
// then register it in the preload cache of the loader before
sap.ui.require.preload({
"sap/m/messagebundle_fa.properties": sapmtext
});
sap.ui.require.preload
is not a public API.Upvotes: 3