0
votes

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.

2
What does the console say? I assume that the model fails to load the bundle.matbtt
@matbtt the console shows the model's object. no errors. the object's _oResourceBundle property has data about locale, but no property files included.keshet
As far as I know you shoud also set the model to the view. If you can say which version you are using I can help more. At older versions I was creating root view at createContent function in Component.js. Then I was setting my model like oView.setModel(oi18nModel, "i18n")melomg
You forgot to give the i18n an URL, where the physical i18n file is lying in your folder structure, the property is called bundleUrl ... without it, no model will ever be instatiated.dotchuZ
@zyrex I just tried to add the following property: bundleUrl:"i18n/i18n.properties", but the model is still empty. The component.js, where I define the model, is in the root folder.keshet

2 Answers

1
votes

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");
1
votes

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.