i18next-node - translation made easy
i18next is a full-featured javascript library for translating your webapplication.
Benefits
- express middleware
- template function
- seo friendly routes
- support for variables
- support for nesting
- support for context
- support for multiple plural forms
- gettext converter
- gettext backend
- yaml backend
- sprintf supported
- detect language
- graceful translation lookup
- get string or object tree
- load resourcefiles from server
- exchangable backends (dbs)
- save missing resources to server
- highly configurable
- post missing resources to server
- custom post processing
- translation ui
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")