1
votes

I want to get rid of i18n files in SAPUI5 applications. I developed an OData service that provides all the translations and removed i18n model from manifest.json. Also I create i18n model based on my OData service in Component.js.But I don't know why the elements does not bind to data of my i18n model.

Here is my code for creating Odata model:

oDataModel.read("/TranslationConfigSet", {
            async: false,
            filters: aFilter,
            success: function(oData, response) {
                var aI18n = {};
                var results = oData.results;
                for (var i = 0; i < results.length; i++) {
                    aI18n[results[i]["ZStringKey"]] = results[i]["ZTranslation"];
                }
                var oI18nModel = new JSONModel(aI18n);
                _this.setModel(oI18nModel, "i18n");
            },
            error: function(oError) {

            }
        });

This code is placed inside of my Component.js file and inside of the xml view files I have some codes like this:

text="{i18n>TESTSTRING}"

While TESTSTRING exists in my data and my array.

1
how did you define "_this" in that case? the idea is great by the way... let the community know if you solve this. great post!dotchuZ
I hope to be able to solve it. var _this=this; outside of the callback function.user7383443
I don't get it, why this should be an good idea? Adding OData related overhead to load translations, storing translations in a JSONModel and having to adopt to a different binding syntax, losing the functionality of the ResourceModel... where is the advantage?matbtt
I don't get it either. @zyrex: Why is it a great idea? Martin: Would you mind to share the reason behind your decision? Why would you want to get translations from the server (and paying an extra synchronous round trip) instead of storing them on the client side? I'm lacking experience in SAP NW/GW stuff, so I'm genuinely curious.Boghyon Hoffmann
@boghyon First it is not related to SAP NW. It is related to SAPUI5. Second manipulation of data in DB is easier than some files.user7383443

1 Answers

2
votes

You seem to have missed the slash(/) in the binding syntax. The binding syntax for a JSON model is different from the Resource bundle syntax. So your binding should be

text="{i18n>/TESTSTRING}"