Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
fastify-i18next
Advanced tools
Changelog
0.5.0
Readme
This is a plugin to use i18next in Fastify, based on i18next-express-middleware.
Source can be loaded via npm.
# npm package
$ npm install fastify-i18next
var i18next = require("i18next");
var fastifyi18next = require("fastify-i18next");
var fastify = require("fastify")({ logger: true });
i18next.use(fastifyi18next.LanguageDetector).init({
preload: ["en", "de"],
resources: {
en: {
translation: {
"title": "Hello World!"
}
},
de: {
translation: {
"title": "Hallo Welt!"
}
}
},
...otherOptions
});
fastify.register(fastifyi18next.plugin, { i18next });
fastify.get('/', async (request, reply) => {
return request.t('title');
});
const start = async () => {
try {
await fastify.listen(3000)
fastify.log.info(`server listening on ${fastify.server.address().port}`)
} catch (err) {
fastify.log.error(err)
process.exit(1)
}
}
start()
Detects user language from current request. Comes with support for:
Wiring up:
var i18next = require("i18next");
var fastifyi18next = require("fastify-i18next");
i18next.use(fastifyi18next.LanguageDetector).init(i18nextOptions);
As with all modules you can either pass the constructor function (class) to the i18next.use or a concrete instance.
{
// order and from where user language should be detected
order: [/*'path', 'session', */ 'querystring', 'cookie', 'header'],
// keys or params to lookup language from
lookupQuerystring: 'lng',
lookupCookie: 'i18next',
lookupHeader: 'accept-language',
lookupSession: 'lng',
lookupPath: 'lng',
lookupFromPathIndex: 0,
// cache user language
caches: false, // ['cookie']
// optional expire and domain for set cookie
cookieExpirationDate: new Date(),
cookieDomain: 'myDomain',
cookieSecure: true // if need secure cookie
}
Options can be passed in:
preferred - by setting options.detection in i18next.init:
var i18next = require("i18next");
var fastifyi18next = require("fastify-i18next");
i18next.use(fastifyi18next.LanguageDetector).init({
detection: options
});
on construction:
var fastifyi18next = require("fastify-i18next");
var lngDetector = new fastifyi18next.LanguageDetector(null, options);
via calling init:
var fastifyi18next = require("fastify-i18next");
var lngDetector = new fastifyi18next.LanguageDetector();
lngDetector.init(options);
module.exports {
name: 'myDetectorsName',
lookup: function(req, res, options) {
// options -> are passed in options
return 'en';
},
cacheUserLanguage: function(req, res, lng, options) {
// options -> are passed in options
// lng -> current language, will be called after init and on changeLanguage
// store it
}
};
var i18next = require("i18next");
var fastifyi18next = require("fastify-i18next");
var lngDetector = new fastifyi18next.LanguageDetector();
lngDetector.addDetector(myDetector);
i18next.use(lngDetector).init({
detection: options
});
FAQs
i18next plugin for fastify, based on i18next-express-middleware
The npm package fastify-i18next receives a total of 8 weekly downloads. As such, fastify-i18next popularity was classified as not popular.
We found that fastify-i18next 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.