softshipper
softshipper

Reputation: 34099

How to extend the translation?

I extend a standard fiori application and I would like to extend i18n also.
The structure of the extended app looks as the following:

enter image description here

And in the Component.js file, I notice the extension:

this.i2d.eam.pmnotification.create.s1.Component.extend("i2d.eam.pmnotification.create.s1.ZEAM_NTF_CRES1_EXT.Component", {
    metadata: {
        manifest: "json",
        config: {
            "sap.ca.i18Nconfigs": {
                bundleName: "i2d.eam.pmnotification.create.s1.ZEAM_NTF_CRES1_EXT.i18n.i18n"
            }
        }
    }
}); 

but the text still does not get translated.

The content of the i18n.properties file:

ext.createNotification=Create notification
ext.createOrder=Create order 

and Buttons, that are using the translation:

<Button press="onCreateWithOrder" text="{i18n>ext.createOrder}" />
<Button press="onSave" text="{i18n>ext.createNotification}"/>  

What am I doing wrong?

Upvotes: 3

Views: 2890

Answers (1)

fabiopagoti
fabiopagoti

Reputation: 1541

I only used "sap.ca.i18Nconfigs"with success when translating apps using the old fashion "scaffolding" namespace (sap.ca.scfld).

I would bet that the app you are extending is not based on it.

Then, try to add the following calls to your Component.js file

init: function() {
        UIComponent.prototype.init.apply(this, arguments);

        var oModel = new sap.ui.model.resource.ResourceModel({
            bundleUrl: "../pathToYourParentApp/i18n/i18n.properties"
        });

        oModel.enhance({
            bundleUrl: "i18n/i18n.properties"
        });

        this.setModel(oModel, "i18n");
        sap.ui.getCore().setModel(oModel, "i18n");

    }

Also, check the example https://github.com/fabiopagoti/ui5-extension

Upvotes: 5

Related Questions