on 2021 Apr 27 4:31 PM
Hi SAP Community,
I’m facing issues with handling multiple languages inside my application. My requirement is to set the particular selected language mentioned in the selection field to the application. The custom texts are set correctly from the corresponding i18n bundles which are changed using the localizationChanged Event.
sap.ui.getCore().attachLocalizationChanged(function (oEvt) {
var oChanges = oEvt.getParameter("changes");
if (oChanges && oChanges.language) {
this._bundle = sap.ui.getCore().getLibraryResourceBundle("sap.m", oChanges.language);
sap.ushell.Container.getService("UserInfo").getUser().setLanguage(oChanges.language.toLocaleUpperCase());
this._setDefaultModel(oChanges.language); // this is the function where I set the language parameters }
}.bind(this));
However, the application’s certain standard texts and backend driven texts ( which are highlighted in the below picture) remains unchanged. I would greatly appreciate your efforts and ideas that could help me solve this issue.
Below are some of my tried and tested methods with little to no luck
Method 1: I tried to directly access the private members of oDataModel and tried to set url parameters as below
var oModel = this.getOwnerComponent().getModel();
oModel.aUrlParams[0] = "sap-language=" + language.toLocaleUpperCase();
oModel.mMetadataUrlParams = {
"sap-language": language.toLocaleUpperCase(),
"sap-value-list": "none"
};
this.getOwnerComponent().setModel(oModel);
This produced a 50-50 result-like, like in the request URL the specified language was appended but in the request payload it still remained as Accept-language:"en" and it did not change the metadata url parameters, so no effect was seen altogether
Method 2: As akshaya1591 suggested in her blog https://blogs.sap.com/2019/09/20/smart-templates-tips-and-tricks/?update=updated, I created a new model with my parameters and tried to load this new model as my default model like below,
var oDefaultModel = this.getView().getModel();
var custSrvUrl = oDefaultModel.sServiceUrl;
var oModel = new sap.ui.model.odata.v2.ODataModel({
serviceUrl: custSrvUrl,
annotationURI: [
"/sap/opu/odata/IWFND/CATALOGSERVICE;v=2/Annotations(TechnicalName='ZService_ANNO_MDL',Version='0001')/$value/",
"../annotations/annotations.xml"
],
serviceUrlParams: {
"sap-language": language.toLocaleUpperCase()
},
metadataUrlParams: {
"sap-language": language.toLocaleUpperCase()
}
});
oModel.fireAnnotationsLoaded(oModel.getServiceAnnotations());
var oMetaModel = oModel.getMetaModel();
oMetaModel.fireRequestCompleted();
this.getView().setModel(oModel);
The url params to my batch call and the metadata call were set successfully using this method and in the "Networks" tab of the debugger I could see the corresponding language files loaded, however, it had two drawbacks
Method 3: I tried to manipulate the manifest file and add runtime parameters from the controller, but it threw an error saying “Cannot read property 'settings' of undefined" as there were only i18n model inside oManifestUi5 object and the default oDatamodel wasn’t there.
var oManifestUi5 = this.getOwnerComponent().getMetadata().getManifestEntry("sap.ui5");
oManifestUi5.models[""].settings.serviceUrlParams["sap-language"] = language.toLocaleUpperCase();
// oManifestUi5.models[].settings.serviceUrlParams["sap-language"] = language.toLocaleUpperCase();
oManifestUi5.models[""].settings.metadataUrlParams["sap-language"] = language.toLocaleUpperCase();
Please correct me if I'm doing it the wrong way or suggest any new ways that could possibly help me in achieving my desired result.
Thanks in advance!!
Regards
Imtiaz N
Request clarification before answering.
Can you check if the language EN is set in the ABAP RFC connection (used by the system alias assigned to your OData service) which connects the front-end system to your back-end system?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
40 | |
15 | |
10 | |
9 | |
5 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.