Hello,
I’m using the Locale Plugin in Webix Jet and trying to make a dynamic webapp and store locale information on the server. Is there a way to access the locale/en.js file and alter the information right before the app has rendered?
Hello,
I’m using the Locale Plugin in Webix Jet and trying to make a dynamic webapp and store locale information on the server. Is there a way to access the locale/en.js file and alter the information right before the app has rendered?
Yep, you can place code like next inside of app’s constructor
var locale = app.getService("locale");
service.polyglot = new Polyglot({ phrases:data });
services.polyglot.locale(lang);
service._ = service.polyglot.t.bind(service.polyglot);
app.refresh();
where
Beautiful… This was exactly what I was looking for. Thanks again!
@maksim what is “service” & “services” in your example? I was able to get it working by doing:
const langs = this.app.getService("locale");
langs.polyglot = new Polyglot({ phrases:{"Viewing User:":'english'} });
langs.polyglot.locale('en');
langs._ = langs.polyglot.t.bind(langs.polyglot);
Also, I’m trying to load the locale data when the app initially loads, so in “myapp.js”. But I’m running into two issues:
I try the following code…
//sources/myapp.js
app.use(plugins.Locale,{lang:'es'});
let locale = this.app.getService("locale");
locale.polyglot = new Polyglot({ phrases:{'Go': 'shit'}});
locale.polyglot.locale('es');
locale._ = locale.polyglot.t.bind(locale.polyglot);
app.refresh();
… before and after app.render(), but neither work. Is there a way to load locales data in “myapp.js”?
Thanks
UPDATE: I figured this out… always after asking.
//sources/myapp.js
// prior to app.render();
let polyglot = new Polyglot();
polyglot.locale('es');
app.use(plugins.Locale,{lang:'es'});
let locale = app.getService("locale");
locale._ = locale.polyglot.t.bind(locale.polyglot);
locale.polyglot.phrases = {'Go': 'ir'};