Socket
Socket
Sign inDemoInstall

i18next

Package Overview
Dependencies
Maintainers
1
Versions
501
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18next - npm Package Compare versions

Comparing version 1.5.16 to 1.6.0

bench/bench.js

2

backends/couchDb/package.json
{
"author": "Jan Muehlemann"
, "name": "i18next.couchdb"
, "version": "1.5.9"
, "version": "1.6.0"
, "contributors": [

@@ -6,0 +6,0 @@ { "name": "Jan Muehlemann", "email": "jan.muehlemann@gmail.com" }

@@ -91,5 +91,5 @@ var cradle = require('cradle');

postMissing: function(lng, ns, key, defaultValue, callback) {
saveMissing: function(lng, ns, key, defaultValue, callback) {
// add key to resStore
var keys = key.split('.');
var keys = key.split(this.options.keyseparator);
var x = 0;

@@ -122,3 +122,3 @@ var value = this.resStore[lng][ns];

// change key in resStore
var keys = key.split('.');
var keys = key.split(self.options.keyseparator);
var x = 0;

@@ -151,3 +151,3 @@ var value = fetched[lng][ns];

// change key in resStore
var keys = key.split('.');
var keys = key.split(self.options.keyseparator);
var x = 0;

@@ -154,0 +154,0 @@ var value = fetched[lng][ns];

{
"author": "Jan Muehlemann"
, "name": "i18next.gettext"
, "version": "1.5.5"
, "version": "1.6.0"
, "contributors": [

@@ -6,0 +6,0 @@ { "name": "Jan Muehlemann", "email": "jan.muehlemann@gmail.com" }

@@ -32,3 +32,3 @@ var converter = require('i18next-conv');

postMissing: function(lng, ns, key, defaultValue, callback) {
saveMissing: function(lng, ns, key, defaultValue, callback) {
console.log('not implemented');

@@ -35,0 +35,0 @@ callback('not implemented');

{
"author": "Jan Muehlemann"
, "name": "i18next.mongoDb"
, "version": "1.5.9"
, "version": "1.6.0"
, "contributors": [

@@ -6,0 +6,0 @@ { "name": "Jan Muehlemann", "email": "jan.muehlemann@gmail.com" }

@@ -38,3 +38,3 @@ var mongo = require('mongodb');

var server = new mongo.Server(options.host, options.port, options.options);
new mongo.Db(options.dbName , server, {}).open(function(err, client) {
new mongo.Db(options.dbName, server, {safe: true}).open(function(err, client) {
if (err) {

@@ -88,5 +88,5 @@ if (callback) callback(err);

postMissing: function(lng, ns, key, defaultValue, callback) {
saveMissing: function(lng, ns, key, defaultValue, callback) {
// add key to resStore
var keys = key.split('.');
var keys = key.split(this.options.keyseparator);
var x = 0;

@@ -119,3 +119,3 @@ var value = this.resStore[lng][ns];

// change key in resStore
var keys = key.split('.');
var keys = key.split(self.options.keyseparator);
var x = 0;

@@ -148,3 +148,3 @@ var value = fetched[lng][ns];

// change key in resStore
var keys = key.split('.');
var keys = key.split(self.options.keyseparator);
var x = 0;

@@ -151,0 +151,0 @@ var value = fetched[lng][ns];

{
"author": "Jan Muehlemann"
, "name": "i18next.redis"
, "version": "1.5.9"
, "version": "1.6.0"
, "contributors": [

@@ -6,0 +6,0 @@ { "name": "Jan Muehlemann", "email": "jan.muehlemann@gmail.com" }

@@ -72,5 +72,5 @@ var redis = require('redis');

postMissing: function(lng, ns, key, defaultValue, callback) {
saveMissing: function(lng, ns, key, defaultValue, callback) {
// add key to resStore
var keys = key.split('.');
var keys = key.split(this.options.keyseparator);
var x = 0;

@@ -103,3 +103,3 @@ var value = this.resStore[lng][ns];

// change key in resStore
var keys = key.split('.');
var keys = key.split(self.options.keyseparator);
var x = 0;

@@ -132,3 +132,3 @@ var value = fetched[lng][ns];

// change key in resStore
var keys = key.split('.');
var keys = key.split(self.options.keyseparator);
var x = 0;

@@ -135,0 +135,0 @@ var value = fetched[lng][ns];

{
"author": "Jan Muehlemann"
, "name": "i18next.remotesync"
, "version": "1.5.14"
, "version": "1.6.0"
, "contributors": [

@@ -6,0 +6,0 @@ { "name": "Jan Muehlemann", "email": "jan.muehlemann@gmail.com" }

@@ -22,5 +22,5 @@ var request = require('request');

postMissing: function(lng, ns, key, defaultValue, callback) {
saveMissing: function(lng, ns, key, defaultValue, callback) {
// add key to resStore
var keys = key.split('.');
var keys = key.split(this.options.keyseparator);
var x = 0;

@@ -51,3 +51,3 @@ var value = this.resStore[lng][ns];

// change key in resStore
var keys = key.split('.');
var keys = key.split(self.options.keyseparator);
var x = 0;

@@ -79,3 +79,3 @@ var value = fetched[lng][ns];

// change key in resStore
var keys = key.split('.');
var keys = key.split(self.options.keyseparator);
var x = 0;

@@ -82,0 +82,0 @@ var value = fetched[lng][ns];

{
"author": "Jan Muehlemann"
, "name": "i18next.yaml"
, "version": "1.5.5"
, "version": "1.6.0"
, "contributors": [

@@ -6,0 +6,0 @@ { "name": "Jan Muehlemann", "email": "jan.muehlemann@gmail.com" }

@@ -25,3 +25,3 @@ var yaml = require('js-yaml')

postMissing: function(lng, ns, key, defaultValue, callback) {
saveMissing: function(lng, ns, key, defaultValue, callback) {
console.log('not implemented');

@@ -28,0 +28,0 @@ callback('not implemented');

@@ -25,6 +25,6 @@ var fs = require('fs');

postMissing: function(lng, ns, key, defaultValue, callback) {
saveMissing: function(lng, ns, key, defaultValue, callback) {
// add key to resStore
var keys = key.split('.');
var keys = key.split(this.options.keyseparator);
var x = 0;

@@ -58,3 +58,3 @@ var value = this.resStore[lng][ns];

// change key in resStore
var keys = key.split('.');
var keys = key.split(self.options.keyseparator);
var x = 0;

@@ -88,3 +88,3 @@ var value = fetched[lng][ns];

// change key in resStore
var keys = key.split('.');
var keys = key.split(self.options.keyseparator);
var x = 0;

@@ -91,0 +91,0 @@ var value = fetched[lng][ns];

@@ -29,3 +29,4 @@ (function() {

options.forceDetectLngFromPath = options.forceDetectLngFromPath !== true ? false : options.forceDetectLngFromPath;
options.supportedLngs = [];
options.detectLngFromHeaders = options.detectLngFromHeaders !== false ? true : options.detectLngFromHeaders;
options.supportedLngs = options.supportedLngs || [];
options.ignoreRoutes = options.ignoreRoutes || [];

@@ -36,3 +37,3 @@ options.cookieName = options.cookieName || 'i18next';

// obsolete
if (options.useSync) console.log('options.useSync is obsolete use i18next.backend(...) instead.');
// if (options.useSync) console.log('options.useSync is obsolete use i18next.backend(...) instead.');

@@ -74,5 +75,6 @@ var o = i18n.functions.extend(i18n.options, options);

}
var locale = i18n.detectLanguage(req, res);
var languages = i18n.functions.toLanguages(i18n.detectLanguage(req, res));
var locale = languages[0];
// set locale & i18n in req

@@ -143,6 +145,14 @@ req.locale = req.lng = req.language = locale;

i18n.serveClientScript = function(app) {
i18n.serveClientScript = function(app, options) {
options = options || {};
var maxAge = options.maxAge || 60 * 60 * 24 * 30;
app.get('/i18next/i18next.js', function(req, res) {
var filename = (process.env.NODE_ENV !== 'production' || process.env.DEBUG) ? __dirname + '/dep/i18next-' + i18n.Version + '.js' : __dirname + '/dep/i18next-' + i18n.Version + '.min.js';
var filename = (process.env.NODE_ENV !== 'production' || process.env.DEBUG) ? __dirname + '/dep/i18next-' + i18n.clientVersion + '.js' : __dirname + '/dep/i18next-' + i18n.clientVersion + '.min.js';
if (process.env.NODE_ENV === 'production' || options.cache) {
res.header('Cache-Control', 'public max-age=' + maxAge);
res.header('Expires', (new Date(new Date().getTime() + maxAge * 1000)).toUTCString());
}
res.sendfile(filename);

@@ -160,3 +170,6 @@ });

i18n.serveDynamicResources = function(app) {
i18n.serveDynamicResources = function(app, options) {
options = options || {};
var maxAge = options.maxAge || 60 * 60 * 24 * 30;
app.get('/locales/resources.json', function(req, res) {

@@ -167,2 +180,6 @@

res.contentType('json');
if (process.env.NODE_ENV === 'production' || options.cache) {
res.header('Cache-Control', 'public max-age=' + maxAge);
res.header('Expires', (new Date(new Date().getTime() + maxAge * 1000)).toUTCString());
}

@@ -169,0 +186,0 @@ var languages = req.query.lng ? req.query.lng.split(' ') : []

(function() {
// when updating dep/i18next.xx.js update version here
var i18nVersion = '1.5.10';
var i18nVersion = '1.6.0';

@@ -11,3 +11,4 @@ var i18n = require('./dep/i18next-' + i18nVersion)

wrapper.Version = i18nVersion;
wrapper.version = require('../package.json').version;
wrapper.clientVersion = i18nVersion;

@@ -18,50 +19,45 @@ if (typeof module !== 'undefined' && module.exports) {

// overriding detect language function
var detectLanguage = function(req, res) {
var querystring, cookies, headers, query, cookie, locale
, locales = []
, opts = wrapper.options;
// detection subfunctions
function detectLanguageFromPath(req, res, options) {
var locale, locales = [];
var parts = req.originalUrl.split('/');
if (parts.length > options.detectLngFromPath) {
var part = parts[options.detectLngFromPath + 1];
var lookUp = wrapper.pluralExtensions.rules[part.split('-')[0]];
if (lookUp) locale = part;
}
if (locale) locales.push({lng: cleanLngString(locale, options), q: 1});
return locales;
}
if (typeof req === 'object') {
function detectLanguageFromQuerystring(req, res, options) {
var locale, locales = [];
if (req.query) {
locale = req.query[options.detectLngQS];
} else {
var querystring = url.parse(req.url, true);
locale = querystring.query[options.detectLngQS];
}
if (locale) locales.push({lng: cleanLngString(locale, options), q: 1});
return locales;
}
if (opts.detectLngFromPath !== false) {
var parts = req.originalUrl.split('/');
if (parts.length > opts.detectLngFromPath) {
var part = parts[opts.detectLngFromPath + 1];
var lookUp = wrapper.pluralExtensions.rules[part.split('-')[0]];
if (lookUp && (opts.supportedLngs.length === 0 || opts.supportedLngs.indexOf(lookUp) > -1)) locale = part;
}
if (!locale && opts.forceDetectLngFromPath) {
locale = opts.fallbackLng;
}
}
if (!locale) {
querystring = url.parse(req.url, true);
if (querystring.search) locale = querystring.query[opts.detectLngQS];
}
if (!locale && opts.useCookie) {
cookies = new Cookies(req, res);
locale = cookies.get(opts.cookieName);
}
if (locale) {
locales.push(locale);
} else {
locales = _extractLocales(req.headers);
}
function detectLanguageFromCookie(req, res, options) {
var locale, locales = [];
if (req.cookies) {
locale = req.cookies[options.cookieName];
} else {
var cookies = new Cookies(req, res);
locale = cookies.get(options.cookieName);
}
if (locale) locales.push({lng: cleanLngString(locale, options), q: 1});
return locales;
}
if (locales.length === 0) locales.push(opts.fallbackLng || 'en');
return locales[0];
};
var _extractLocales = function(headers) {
var detectLanguageFromHeader = function(req, res, options) {
var headers = req.headers;
var locales = [];
if (!headers) {
return i18n.options.fallbackLng;
return locales;
}

@@ -72,3 +68,3 @@

if (acceptLanguage) {
var lngs = [];
var lngs = [], i;

@@ -81,3 +77,3 @@ // associate language tags by their 'q' value (between 1 and 0)

var qvalue = 1; // default qvalue
var i;
for (i = 0; i < parts.length; i++) {

@@ -92,3 +88,3 @@ var part = parts[i].split('=');

// add the tag and primary subtag to the qvalue associations
lngs.push({lng: parts[0], q: qvalue});
lngs.push({lng: cleanLngString(parts[0], options), q: qvalue});
});

@@ -101,13 +97,82 @@

for (i = 0; i < lngs.length; i++) {
locales.push(lngs[i].lng);
locales.push(lngs[i]);
}
}
return locales;
};
function checkAgainstSupportedLng(locales, supportedLngs) {
if (!supportedLngs.length && locales.length) {
return [locales[0]];
} else {
locales.push(i18n.options.fallbackLng);
for (var i = 0, len = locales.length; i < len; i++) {
var locale = locales[i];
if (supportedLngs.indexOf(locale.lng) > -1) {
return [locale];
}
if (locale.lng.indexOf('-') > -1) {
var unspecific = locale.lng.split('-')[0];
if (supportedLngs.indexOf(unspecific) > -1) {
locale.lng = unspecific;
return [locale];
}
}
}
}
return [];
}
return locales;
function cleanLngString(lng, options) {
if (typeof lng === 'string' && lng.indexOf('-') > -1) {
var parts = lng.split('-');
lng = options.lowerCaseLng ?
parts[0].toLowerCase() + '-' + parts[1].toLowerCase() :
parts[0].toLowerCase() + '-' + parts[1].toUpperCase();
}
return lng;
}
// overriding detect language function
var detectLanguage = function(req, res) {
var locales = []
, opts = wrapper.options;
if (typeof req === 'object') {
// from path
if (opts.detectLngFromPath !== false) {
locales = detectLanguageFromPath(req, res, opts);
locales = checkAgainstSupportedLng(locales, opts.supportedLngs);
if (!locales.length && opts.forceDetectLngFromPath) {
locales = [{lng: opts.fallbackLng, q: 1}];
}
}
// from querystring
if (!locales.length) {
locales = detectLanguageFromQuerystring(req, res, opts);
locales = checkAgainstSupportedLng(locales, opts.supportedLngs);
}
// from cookie
if (!locales.length && opts.useCookie) {
locales = detectLanguageFromCookie(req, res, opts);
locales = checkAgainstSupportedLng(locales, opts.supportedLngs);
}
// from headers
if (!locales.length && opts.detectLngFromHeaders) {
locales = detectLanguageFromHeader(req, res, opts);
locales = checkAgainstSupportedLng(locales, opts.supportedLngs);
}
}
if (!locales.length) locales.push({lng: opts.fallbackLng || 'en', q: 1});
return locales[0].lng;
};
// overriding for the functions in i18next.js

@@ -168,2 +233,7 @@ var f = {

detectLanguage: detectLanguage,
detectLanguageFromPath: detectLanguageFromPath,
detectLanguageFromQuerystring: detectLanguageFromQuerystring,
detectLanguageFromCookie: detectLanguageFromCookie,
detectLanguageFromHeader: detectLanguageFromHeader,
checkAgainstSupportedLng: checkAgainstSupportedLng,

@@ -243,2 +313,20 @@ cookie: {

postMissing: function(lng, ns, key, defaultValue) {
var self = this
, lngs = [];
if (this.options.sendMissingTo === 'fallback') {
lngs.push(this.options.fallbackLng);
} else if (this.options.sendMissingTo === 'current') {
lngs.push(lng);
} else if (this.options.sendMissingTo === 'all') {
lngs = i18n.functions.toLanguages(lng);
}
f.each(lngs, function(i, l) {
self.saveMissing(l, ns, key, defaultValue);
});
},
_loadLocal: function(lngs, cb) {

@@ -252,2 +340,3 @@ cb('not supported');

});
f.extend(wrapper, i18n);

@@ -254,0 +343,0 @@ wrapper.detectLanguage = f.detectLanguage;

@@ -132,2 +132,3 @@ var express;

options = options || {};
options.i18nextWTOptions = extend(defaults.i18nextWTOptions, options.i18nextWTOptions || {}); // extend inner opts
options = extend(defaults, options);

@@ -134,0 +135,0 @@

@@ -5,3 +5,3 @@ {

"description": "i18n made easy - full featured: middleware, template support plus clientside use",
"version": "1.5.16",
"version": "1.6.0",
"repository": {

@@ -29,2 +29,4 @@ "type": "git",

, "jade": ">=0.0.1"
, "benchmark": ">=0.0.1"
, "microtime": ">=0.0.1"
},

@@ -31,0 +33,0 @@ "scripts": {

@@ -0,1 +1,8 @@

### v1.6.0
- supportedLngs now used for all detect functions too
- sendMissingTo Option is now working on server too
- option to disable lng lookup from headers
- fixed setting supported lngs via options
- fixed setting options for webtranslate
### v1.5.15

@@ -2,0 +9,0 @@ - fixed missing argument in remove route

@@ -107,2 +107,3 @@ var i18n = require('../index')

preload: [],
supportedLngs: [],
lowerCaseLng: false,

@@ -150,3 +151,3 @@ ns: 'ns.test',

sync.postMissing('en-US', 'ns.test', 'testKey', 'testTrans', function(err) {
sync.saveMissing('en-US', 'ns.test', 'testKey', 'testTrans', function(err) {
expect(err).to.not.be.ok();

@@ -160,3 +161,3 @@ done();

sync.postMissing('en-US', 'ns.test', 'testKey', 'testTrans', function(err) {
sync.saveMissing('en-US', 'ns.test', 'testKey', 'testTrans', function(err) {
sync.fetchOne('en-US', 'ns.test', function(err, data) {

@@ -200,3 +201,3 @@ expect(data.testKey).to.eql('testTrans');

sync.postMissing('en-US', 'ns.test', 'toRemove', 'testTrans', function(err) {
sync.saveMissing('en-US', 'ns.test', 'toRemove', 'testTrans', function(err) {
sync.postRemove('en-US', 'ns.test', 'toRemove', function(err) {

@@ -212,3 +213,3 @@ expect(err).to.not.be.ok();

sync.postMissing('en-US', 'ns.test', 'toRemove', 'testTrans', function(err) {
sync.saveMissing('en-US', 'ns.test', 'toRemove', 'testTrans', function(err) {
sync.postRemove('en-US', 'ns.test', 'toRemove', function(err) {

@@ -215,0 +216,0 @@ sync.fetchOne('en-US', 'ns.test', function(err, data) {

@@ -14,2 +14,3 @@ var i18n = require('../index')

preload: [],
supportedLngs: [],
lowerCaseLng: false,

@@ -16,0 +17,0 @@ ns: 'translation',

@@ -14,2 +14,3 @@ var i18n = require('../index')

preload: [],
supportedLngs: [],
lowerCaseLng: false,

@@ -16,0 +17,0 @@ ns: 'translation',

@@ -15,2 +15,3 @@ var i18n = require('../index')

preload: ['en', 'de'],
supportedLngs: [],
lowerCaseLng: false,

@@ -17,0 +18,0 @@ ns: 'translation',

@@ -15,2 +15,3 @@ var i18n = require('../index')

preload: ['en', 'de'],
supportedLngs: [],
lowerCaseLng: false,

@@ -17,0 +18,0 @@ ns: 'translation',

Sorry, the diff of this file is too big to display

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