'Localization in node.js with express

Which package do you use for localization with express in node.js?

Thanks!



Solution 1:[1]

node-localize can work together with express.

Depending on where you want the localization, jqtpl-express-i18n can do the job for templating.

Solution 2:[2]

https://github.com/jeresig/i18n-node-2

John Resig's implementation

His blog post on it

http://ejohn.org/blog/i18n-module-for-node-and-express-js/

Solution 3:[3]

Actually I use this NPM Package i18n

It have a very simple usage with Express framework... create locales folder (it.json, en.json, etc...)

// load modules at bootstrap
var app = express();
var i18n = require("i18n");

//set configuration
i18n.configure({
  locales:['en', 'de'],
  directory: __dirname + '/server/locales'
});
app.use(i18n.init);


// and then, in controller we can use response
res__('YOUR_KEY')

Front End side just set the HTTP header Accept-Language with value 'en', 'it', etc.

Solution 4:[4]

here's a great collection of the best ones: https://openbase.com/categories/js/best-nodejs-localization-libraries

you may also find useful these article about the node.js localization basics: https://blog.crowdin.com/2022/03/17/node-js-i18n-localization-for-developers/

Solution 5:[5]

You can use language-translator library. It uses json files to load texts. You can define languages whatever you want.

  • It supports parametrized requests.(that contains :parameter)
  • It supports output text both of route file and view file.
  • It is fully customizable.
  • It uses and manage cookie to know user preference.
  • It loads language file in middleware function by matching your route path and language file. No needs to require language files in every route file.
  • It translates default language's json files' texts by using Yandex translate API. (Free)

Solution 6:[6]

I used localizify library in own project, it's very light.

const localizify = require('localizify');

// ...

app.configure(() => {
    app.use((request, response, next) => {
        const lang = request.headers['accept-language'] || 'en';
        localize.setLocale(lang);
        next();
    });
});

Solution 7:[7]

I found few of the best libraries to deal with localization in nodeJS:

  1. node-gettext - https://www.npmjs.com/package/node-gettext
  2. globalize - https://www.npmjs.com/package/globalize
  3. i18n - https://www.npmjs.com/package/i18n

Solution 8:[8]

node-localize can work for Localization in node.js with express.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ruben Verborgh
Solution 2 liangzan
Solution 3 Alessio Campanelli
Solution 4 Diana Voroniak
Solution 5
Solution 6
Solution 7 Ravi Sharma
Solution 8 Vishal Chodvadiya