i18n-express-4plugin
This is the first experimental version!!! Please do not use it yet
This repository is based on Facu ZAK's 'i18n-express'. The difference is the option, to add further translation paths. This was necessary for me in a plug-in system, since additional modules had to be dynamically loaded there.
Now in the running system, you can add more translation paths.
In your post-loaded module...
var i18n=; i18n;
Requirements
- Node >= 0.12
- Express.js
Installation
$ npm install i18n-express-4plugin
Usage
var i18n=; app;
Options
translationsPath
: (default:i18n
) The path where you store translations json files.cookieLangName
: (default:ulang
) If you provide a cookie name, try to get user lang from this cookie.browserEnable
: (default:true
) If enabled, try to get user lang from browser headers.defaultLang
: (default:en
) If all others methods fail, use this lang.paramLangName
: (default:clang
) Get param to change user lang. ej: visiting 'example.com?clang=es' the lang switchs to 'es'siteLangs
: (default:['en']
) Array of supported langs. (posbile values for clang and json files)textsVarName
: (default:texts
) Name of variable which holds the loaded translations.
Example
Create a directory "i18n" with .json files for each lang. Ej:
- en.json
- es.json
- en-us.json
With translations like this (en.json):
In your Express app.js:
var express = ;var path = ;var cookieParser = ;var bodyParser = ;var i18n=; // <-- require the module var indexRoutes = ; var app = ; // view engine setupapp;app;app;app;app; app;... app; moduleexports = app; ...
Within your plugin, you can add another translation paths...
i18n;
Now in your ejs view you have texts
object and lang
variable with the active language:
Choose your language: Spanish English <%=translation.WELCOME_MSG%>
Or in your handlebars view:
Choose your language: Spanish English {{translation.WELCOME_MSG}}
License
MIT