express-adam-locale
Simple Multi Language Middleware for Express.
Installation
$ npm install express-adam-locale --save
Example
app.js:
var Path = ;var express = ;var EAL = ;var session = ;var app = ; app; /* i18n */app; /* templating */app;app;app; /* page */app; app
i18n/en-us.json
views/locale.ejs
<%= _i18n_.hello %>, <%= _i18n_.world %>.current:<%= _i18n_current_ %>.<% for(var i in _i18n_supported_) { %> switch to <%= _i18n_supported_[i].lang %> <% } %>
Options
path {String}
The folder path of i18n files
supported {Array}
The supported languages. default value: [{code:'en-us', lang:'English'},{code:'zh-cn', lang:'简体中文'}]
Example:
app;
default {String}
Default language
set_url {String}
The url to switch current language. default value: /set_locale
Example:
app;
Then you can set current language by request url like this '/set_locale?lang=en-us'
Local Params
The following three params are set to res.locals
res.locals._i18n_
{Object}res.locals._i18n_current_
{String}res.locals._i18n_supported_
{Array}
Debug
Set the DEBUG
environment variable to express-adam-locale
when starting your server.
$ DEBUG=express-adam-locale
License
MIT