mashpie/i18n-node — pull request #91 by davidkalosi (2013-12-28 18:46:32+00:00)
Title: Custom storage backed and initialization

Hi,

no idea if anybody will find this interesting but here are some changes I implemented in order to enable loading from different sources then files. Our application stores all the translation messages as well as the list of supported locales in the database so I came up with this idea how to define custom storage backends without any hard dependencies to specific db drivers or ORMs.

the locales parameter can accept a closure with a callback parameter that is the actual locale that is being loaded.
then i added a reader parameter that recieves 2 parameters - one is the locale from the first function and the second param is the array of locales.

the code bellow is my initialization using sequelize.js.

```node
i18n.configure({
defaultLocale: 'en',
updateFiles: false,
locales: function (callback) {
db.Intl.Locale.findAll().success(function (locales) {
locales.forEach(function(locale) {
callback(locale);
});
});
},
reader: function(locale, result) {
result[locale.locale] = {};

db.Intl.Error.findAll({where: {locale_id: locale.id}}).success(function (rows) {
rows.forEach(function(row) {
result[locale.locale][row.key] = row.message;
});
});
}
});
```
another feature I have added is support for ```%text%``` style Symfony placeholders since we are sharing localization data between a Symfony 2 and node application.
This call handles the %id% placeholder in the text.

```node
res.__('intl.locale.notfound', {id: req.params.id})
```

david