
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
express-adam-locale
Advanced tools
Simple Multi Language Middleware for Express.
$ npm install express-adam-locale --save
app.js:
var Path = require('path');
var express = require('express');
var EAL = require('../index');
var session = require('express-session');
var app = express();
app.use(session({
secret: 'express-adam-locale'
}));
/* i18n */
app.use(EAL({
path: Path.resolve(__dirname, 'i18n'),
supported:[{
code:'en-us',
lang:'English'
}, {
code:'zh-cn',
lang:'中文简体'
}]
}, app));
/* templating */
app.set('view engine', 'ejs');
app.set('views', __dirname + '/views');
app.engine('html', require('ejs').renderFile);
/* page */
app.get('/', function(req, res){
res.render('locale');
});
app.listen(process.argv[2])
i18n/en-us.json
{
"hello": "hello",
"world": "world"
}
views/locale.ejs
<p><%= _i18n_.hello %>, <%= _i18n_.world %>.</p>
<p>current:<%= _i18n_current_ %>.</p>
<% for(var i in _i18n_supported_) { %>
<a href='/set_locale?lang=<%= _i18n_supported_[i].code %>'>
switch to <%= _i18n_supported_[i].lang %>
</a>
<% } %>
The folder path of i18n files
The supported languages. default value: [{code:'en-us', lang:'English'},{code:'zh-cn', lang:'简体中文'}]
app.use(EAL({
path: Path.resolve(__dirname, 'i18n'),
supported: [{code:'en-us', lang:'English'},{code:'zh-cn', lang:'简体中文'}]
}, app));
Default language
The url to switch current language. default value: /set_locale
app.use(EAL({
path: Path.resolve(__dirname, 'i18n'),
set_url: '/set_locale'
}, app));
Then you can set current language by request url like this '/set_locale?lang=en-us'
The following three params are set to res.locals
res.locals._i18n_
{Object}res.locals._i18n_current_
{String}res.locals._i18n_supported_
{Array}Set the DEBUG
environment variable to express-adam-locale
when starting your server.
$ DEBUG=express-adam-locale
MIT
FAQs
Simple Multi Language Middleware for Express.
The npm package express-adam-locale receives a total of 5 weekly downloads. As such, express-adam-locale popularity was classified as not popular.
We found that express-adam-locale demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.