EddyVerbruggen / nativescript-localize

Internationalization plugin for NativeScript using native capabilities of each platform
MIT License
79 stars 31 forks source link

Empty controls #17

Closed daresh closed 6 years ago

daresh commented 6 years ago

Hi!

I have an issue with the localize plugin. I have a simple app with two pages.

XML of page 1: `

`

The other page works fine, all the texts are in place and translated.

The lang file en.default.js: module.exports = { "app.name": "Rorschach Test", "welcome" : "Welcome!!", "start.test" : "Start the test", "q1.ans1" : "answer1" }

NativeScript Core, Windows 10, target platform android, everything is a fresh install (latest versions).

daresh commented 6 years ago

Weird, but it started working after I added some empty observable and bound it: const observableModule = require("data/observable"); const context = new observableModule.fromObject({}); exports.onLoaded = function (args) { page = args.object; page.bindingContext = context; };

Don't know if it's a bug or a feature, you may take a look at it :)

lfabreges commented 6 years ago

Not a bug nor a feature, it seems that you have to add a bindingContext to access application resources, if you take a look at the demo, I just do page.bindingContext = {};

daresh commented 6 years ago

Thanks! So it's just a thing to remember :)

Is it possible to localize also code in JS, like for example alert messages using your plugin?

lfabreges commented 6 years ago

Yes you can, just use the localize function directly:

const localize = require("nativescript-localize").localize;