translate datacollection Localization

Hi,

How to get language to translate in a datacolection?, for example

in a jetview i get translation by this way, example:

/*user.js*/
export default class UserView extends JetView {
    config() {
        
        const _ = this.app.getService("locale")._;
        
         var titlebar = { view: "template", template:"_(title_bar)", type: "header", fillspace: true };

          return titlebar;
    }
}

But in records.js file, i have datacollections only.

It’s possible to get the translations in this type of files?.

I want to import records.js to other classes but already translated the datacollections.

/*records.js*/
const _ = this.app.getService("locale")._;

export const dataColOne = new webix.DataCollection({
    data: [
        { id: 1, title: _("title_1") },
        { id: 2, title: _("title_2") },
        { id: 3, title: _("title_3") }
    ]
});

export const dataColTwo = new webix.DataCollection({
    data: [
        { id: 1, title: _("word_1") },
        { id: 2, title: _("word_2") },
        { id: 3, title: _("word_3") }
    ]
});

In this case “const _ = this.app.getService(“locale”)._” I get the error “this.app is undefined”, obviously.

Possibly my approach is not correct, I do not know how to do this, any help is appreciated.

Thanks in advance.

Models are not bound to the app by default.
You can convert them to services like next

//app.js
import {records} from "models/records";

class MyApp extends JetApp {
   constructor(config){
       ...
     this.setService("records", records(this));
   }
}

and in the model

/*records.js*/
export default function init(app){
  const _ = app.getService("locale")._;

  const dataColOne = new webix.DataCollection({
    data: [
        { id: 1, title: _("title_1") },
        { id: 2, title: _("title_2") },
        { id: 3, title: _("title_3") }
    ]
  });

  const dataColTwo = new webix.DataCollection({
    data: [
        { id: 1, title: _("word_1") },
        { id: 2, title: _("word_2") },
        { id: 3, title: _("word_3") }
    ]
  });

  return { dataColOne, dataColTwo }
}

Now, in place, where you need to obtain the model, just use

this.app.getService("records").dataColOne

Thanks so much!!! work perfect!!