Localization in node.js with express [closed]
Asked Answered
P

7

27

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

Thanks!

Panatella answered 25/7, 2012 at 8:36 Comment(0)
C
11

node-localize can work together with express.

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

Coastline answered 25/7, 2012 at 12:10 Comment(0)
B
9

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.

Backsaw answered 5/3, 2019 at 10:29 Comment(0)
V
8

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/

Vannessavanni answered 19/7, 2013 at 2:22 Comment(0)
T
2

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)
Triatomic answered 11/7, 2018 at 19:20 Comment(0)
D
2

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
Dorella answered 27/3, 2022 at 14:1 Comment(0)
P
1

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();
    });
});
Python answered 27/3, 2017 at 8:19 Comment(0)
C
0

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

Casaba answered 11/4, 2022 at 10:39 Comment(1)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewInterrogation

© 2022 - 2024 — McMap. All rights reserved.