I'm developing a proyect in nodejs, I want to add a feature for language translation.
Checking on internet i saw 2 options that seem ok (i18n and i18n-2).
I have added the proper code in my server side in order to configure it.
In express.js
var i18n = require('i18n-2');
i18n.expressBind(app, {
// setup some locales - other locales default to vi silently
locales: ['es', 'en'],
// set the default locale
defaultLocale: 'en',
// set the cookie name
cookieName: 'locale',
extension: ".json"
});
app.use(function(req, res, next) {
req.i18n.setLocaleFromQuery();
req.i18n.setLocaleFromCookie();
next();
});
So if in this same file I put this code below, it's suppose to print in english language because of the defaultLocale but it prints in Spanish
var i18n2 = new (require('i18n-2'))({
locales: ['es', 'en'],
// set the default locale
defaultLocale: 'en',
// set the cookie name
cookieName: 'locale',
extension: ".json"
});
console.log("Mensaje de i18n");
console.log( i18n2.__("hola") );
Apart of this question, I want to know how I can send this i18n variable to the client side in order to use it in the views of templates or if I have to create another one.
Greetings