Socket
Socket
Sign inDemoInstall

i18next-express-middleware

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18next-express-middleware - npm Package Compare versions

Comparing version 0.4.0 to 1.0.0

3

CHANGELOG.md

@@ -0,3 +1,6 @@

### 1.0.0
- use an i18next instance clone instead of a pseudo/mock object, keep clone lng and req.lng in sync
### 0.4.0
- adds localized routes
- adds default export for es6 users not want to use named exports.default

46

lib/index.js

@@ -7,5 +7,2 @@ 'use strict';

exports.LanguageDetector = undefined;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
exports.handle = handle;

@@ -39,2 +36,9 @@ exports.getResourcesHandler = getResourcesHandler;

var i18n = i18next.cloneInstance();
i18n.on('languageChanged', function (lng) {
// Keep language in sync
req.language = req.locale = req.lng = lng;
req.languages = i18next.services.languageUtils.toResolveHierarchy(lng);
});
var lng = req.lng;

@@ -44,4 +48,3 @@ if (!req.lng && i18next.services.languageDetector) lng = i18next.services.languageDetector.detect(req, res);

// set locale
req.language = req.locale = req.lng = lng || i18next.options.fallbackLng[0];
req.languages = i18next.services.languageUtils.toResolveHierarchy(lng);
i18n.changeLanguage(lng || i18next.options.fallbackLng[0]);

@@ -52,35 +55,8 @@ if (req.i18nextLookupName === 'path' && options.removeLngFromUrl) {

// assert t function returns always translation
// in given lng inside this request
var t = function t(key, options) {
options = options || {};
if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) !== 'object' && i18next.options.overloadTranslationOptionHandler && typeof i18next.options.overloadTranslationOptionHandler === 'function') {
options = i18next.options.overloadTranslationOptionHandler(arguments);
}
options.lng = options.lng || req.lng;
return i18next.t(key, options);
};
var t = i18n.t.bind(i18n);
var exists = i18n.exists.bind(i18n);
var exists = function exists(key, options) {
options = options || {};
options.lng = options.lng || req.lng;
return i18next.exists(key, options);
};
var i18n = {
t: t,
exists: exists,
dir: function dir(lng) {
return i18next.dir(lng);
},
changeLanguage: function changeLanguage(lng) {
req.language = req.locale = req.lng = lng;
req.languages = i18next.services.languageUtils.toResolveHierarchy(lng);
},
language: lng
};
// assert for req
req.i18n = i18n;
req.t = req.t || t;
req.t = t;

@@ -87,0 +63,0 @@ // assert for res -> template

{
"name": "i18next-express-middleware",
"version": "0.4.0",
"version": "1.0.0",
"description": "express middleware for i18next",

@@ -22,4 +22,4 @@ "main": "./lib/index.js",

"devDependencies": {
"babel-cli": "6.5.1",
"babel-core": "6.7.4",
"babel-cli": "6.7.7",
"babel-core": "6.7.7",
"babel-eslint": "5.0.0",

@@ -29,3 +29,3 @@ "babel-preset-es2015": "6.3.13",

"chai": "2.3.0",
"eslint": "2.4.0",
"eslint": "2.7.0",
"mocha": "2.2.5",

@@ -32,0 +32,0 @@ "sinon": "1.17.1"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc