keshet
keshet

Reputation: 1826

i18n Model is empty

I try to implement i18n model in my app, but for some reason the model stays empty no matter what I tried to do.

I use WEB IDE and I have to work with a project which was created by somebody else. The structure of the project is different from the standard SAPUI5 app (there is no manifest.json, no webapp folder, the Component.js looks different etc.).

What I've already tried to do is to declare the i18n model in the component.js and bind it to the core:

var i18nModel = new sap.ui.model.resource.ResourceModel({
    bundleName:"generated.app.i18n.i18n"
});
sap.ui.getCore().setModel(i18nModel, "i18n");

in the init() function of the component.js ("generated.app" is a namespace).

And than in my view:

<m:Page title="{i18n>title}">
.....
</m:Page>

The structure of the project looks like follows:

-Project_Name

|--view

|--i18n/i18n.properties

|--....

...

I also tried to declare the model in the controller, but it didn't work either.

In both cases the model is created, but it's empty.

i18n.properties is present and has values.

What do I do wrong?

Thank you.

Upvotes: 1

Views: 868

Answers (2)

keshet
keshet

Reputation: 1826

Nothing worked, so I've created a new standard SAPUI5 project and moved the code from the old project. The i18n model works fine now.

Upvotes: 1

dotchuZ
dotchuZ

Reputation: 2641

Try this during init-function in component.js:

// always use absolute paths relative to our own component
// (relative paths will fail if running in the Fiori Launchpad)
var sRootPath = jQuery.sap.getModulePath("your_application_name");

// set i18n model
var i18nModel = new sap.ui.model.resource.ResourceModel({
    bundleUrl : [
        sRootPath, mConfig.resourceBundle
    ].join("/")
});

this.setModel(i18nModel, "i18n");

Upvotes: 1

Related Questions