i18next-node - translation made easy

i18next is a full-featured javascript library for translating your webapplication.

node.js:

npm install i18next

Benefits

  1. express middleware
  2. template function
  3. seo friendly routes
  4. support for variables
  5. support for nesting
  6. support for context
  7. support for multiple plural forms
  8. gettext converter
  9. gettext backend
  10. yaml backend
  11. sprintf supported
  12. detect language
  13. graceful translation lookup
  14. get string or object tree
  15. load resourcefiles from server
  16. exchangable backends (dbs)
  17. save missing resources to server
  18. highly configurable
  19. post missing resources to server
  20. custom post processing
  21. translation ui

  22. something missing?

Documentation


Usage Sample

installation:

npm install i18next

Add your resourcefile under /locales/en-US/translation.json:

{
 
"app": {
   
"name": "i18next"
 
},
 
"creator": {
   
"firstname": "Jan",
   
"lastname": "Mühlemann"
 
}
}

init and translate:

var i18n = require("i18next");

i18n
.init(function(t) {
  i18n
.t("my.key")
});

Usage with express

init i18next:

var i18n = require("i18next");

i18n
.init(function(err, t) {
  i18n
.t("my.key.toLookUp")
});

Register Handler:

// Configuration block of express app
app
.configure(function() {
    app
.use(express.bodyParser());
    app
.use(i18n.handle);
    app
.use(app.router);

   
// ...
});

Register AppHelper so you can use the translate function inside template:

i18n.registerAppHelper(app)

template code (eg. jade):

// sample in jade
body
    span
= t("my.key.toLookUp")