2.1.5 • Published 9 years ago

i18n-node v2.1.5

Weekly downloads
561
License
-
Repository
github
Last release
9 years ago

I18n node

Super simple i18n library with express middleware and Mustache syntax.

Installation

$ npm install i18n-node

Features

  • Based on Mustache syntax (full partials support)
  • Reads translations from file system
  • Simple
  • Automatically detects locale
  • Easy translation method
  • Post processors

Why

We wanted a simple i18n library built on top of the logic-less template syntax provided by Mustache. Most libraries use sprintf, which is awesome, but it requires a specific order of data, which isn't desirable in our case.

Locales

All locales must conform to the locale format ll_CC, where ll is a two-letter language code, and CC is a two-letter country code. For instance, en_US represents U.S. English.

Examples

An example of a locale file could be:

{
	"common:hello": "Hello {{name}}!"
}
var I18n = require('i18n-node');
var i18n = new I18n({
	directory: __dirname + '/locales/'
});
i18n.t('en_US', 'common:hello', {
	name: 'guest'
}); // => "Hello guest!"

Using Middleware

var I18n = require('i18n-node');
var express = require('express');
var app = express();
var i18n = new I18n({
	directory: __dirname + '/locales/'
});

app.configure(function () {
	app.use(i18n.middleware());
	app.use(app.router);
});

app.get('/', function (req, res) {
	res.send(req.t('common:hello', {
		name: 'guest'
	}));
});

Future Stuff

  • Singular/plural support
  • Number formatting across locales taking imperial countries into account
  • Unit tests!

Hope you like it!

2.1.5

9 years ago

2.1.4

9 years ago

2.1.3

10 years ago

2.1.2

10 years ago

2.1.1

10 years ago

2.1.0

10 years ago

2.0.16

11 years ago

2.0.15

11 years ago

2.0.14

11 years ago

2.0.13

11 years ago

2.0.12

11 years ago

2.0.11

11 years ago

2.0.1

11 years ago

2.0.0

11 years ago