i18next/i18next-node-remote-backend

Promise or callback (require return promise)

Closed this issue ยท 5 comments

adyz commented

I am new to the node world, but I've used the i18next plugin in the browser and it works very well for me and now I want to implement this into a node app.

My translate module looks like this:

        var i18next = require('i18next');
        Backend = require('i18next-node-remote-backend');
        var translate = i18next
            .use(Backend)
            .init({
                lng: 'ro',
                backend: {

                    crossDomain: true,

                    // path where resources get loaded from
                    loadPath: 'http://example.com/language/{{lng}}',

                    allowMultiLoading: false
                }
            });

        module.exports = translate;

With express, for each page I init i18next this like

    var translate = require('./translate'); 

Thing is that sometimes the loadPath takes a while to load and I need to know when this is done.

Maybe there is a technique to require module with that executes later on node that I don't know about, but does this returns a function of sort or any way to know when the resources are loaded?

Thanks a ton and the new version looks awesome!

Great job.

some side note: http://locize.com adds some value on top of i18next...

adyz commented

Thanks for helping.

In node/express I used i18next-express-middleware as u recommended and i18next-node-remote-backend to fetch the data from the remove API like so:

    i18next
        .use(i18next_middleware.LanguageDetector)
        .use(i18next_backend)
        .init({
          lng: appShell.params.lang,
          debug: false,
          fallbackLng: false,
          backend: {
            loadPath: appShell.params.apiUrl + 'translate?key=all&&_format=json&language={{lng}}',
            crossDomain: true
          }

        });

Thanks for the great work!

so all working - or you still got some issue?

adyz commented

All good! Works like charm now, no memory leaks, no nothing (I posted another issue here with the memory leaks)