New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

i18n-abide

Package Overview
Dependencies
Maintainers
3
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18n-abide - npm Package Compare versions

Comparing version 0.0.10 to 0.0.11

package.json~

22

docs/API.md

@@ -50,3 +50,3 @@ # API

The following example shows how to set the locale of the request to `zh_TW`
(Traditional Chinese):
(Traditional Chinese):

@@ -76,2 +76,20 @@ exports.homepage = function(req, resp) {

For example, the `es` language listed above should be located at
`i18n/es/messages.plist`.
`i18n/es/messages.plist`.
## format_fn_name Option
For compatibility with `express-resource` and other apps,
you may use the `format_fn_name` option to rename the `format` function.
Example:
app.use(i18n.abide({format_fn_name: 'i18nformat'}));
app.get('/foo', function(req, res) {
res.render('bar', {
greeting: req.i18nformat("%s %s!", ["Hello", "World"]);
});
});
# in bar.ejs
<p><%= i18nformat(gettext("Please see %s"), ["https://example.com"]) %></p>

@@ -62,3 +62,3 @@ /* This Source Code Form is subject to the terms of the Mozilla Public

// We expect to use PO->json files, unless configured to use another format.
options.translation_type = options.translation_type || 'po';
options.translation_type = options.translation_type || 'po';
// Only check URL for locale if told to do so.

@@ -190,5 +190,18 @@ options.locale_on_url = options.locale_on_url === true;

locals.format = format;
req.format = format;
var formatFnName = 'format';
if (!! locals.format || !! req.format) {
if (!! options.format_fn_name) {
formatFnName = options.format_fn_name;
} else {
console.error("It appears you are using middleware which " +
"already sets a variable 'format' on either the request " +
"or reponse. Please use format_fn_name in options to " +
"override this setting.");
throw new Error("Bad Config - override format_fn_name");
}
}
locals[formatFnName] = format;
req[formatFnName] = format;
locals.setLocale = function(assignedLocale) {

@@ -195,0 +208,0 @@ if (translations[assignedLocale]) {

2

package.json

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

"description": "Express/connect module for Node i18n and l10n support",
"version": "0.0.10",
"version": "0.0.11",
"homepage": "https://github.com/mozilla/i18n-abide",

@@ -8,0 +8,0 @@ "repository": {

@@ -163,4 +163,134 @@ #!/usr/bin/env node

var makeResp = function(_locals) {
return {
locals: function(args, orValue) {
if ('string' === typeof args) {
_locals[args] = orValue;
} else {
Object.keys(args).forEach(function(key) {
_locals[key] = args[key];
});
}
}
};
};
suite.addBatch({
"i18n.abide middleware is setup": {
topic: function(){
var middleware = i18n.abide({});
var that = this;
var _locals = {};
var req = {
headers: {
'accept-language': "pl,fr-FR;q=0.3,en-US;q=0.1"
}
};
middleware(req, makeResp(_locals), function() {
// The request and response objects both get
// references to i18n related variables and fn
// Example: req.lang as well as _locals.lang
[req, _locals].forEach(function(obj){
assert.equal(obj.lang, 'en-US');
assert.equal(obj.locale, 'en_US');
assert.ok(obj.format);
assert.equal(typeof obj.format, 'function');
assert.ok(obj.setLocale);
assert.equal(typeof obj.setLocale, 'function');
assert.ok(obj.gettext);
assert.equal(typeof obj.gettext, 'function');
});
that.callback();
});
},
'gets a callback': function(err) {
assert.ok(! err);
}
}
});
suite.addBatch({
"i18n.abide middleware detects format conflict": {
topic: function(){
var middleware = i18n.abide({});
var that = this;
var _locals = {};
var req = {
headers: {
'accept-language': "pl,fr-FR;q=0.3,en-US;q=0.1"
},
// format from express-resource
format: function() {
}
};
_locals.format = req.format;
try {
console.log('== calling middleware');
middleware(req, makeResp(_locals), function() {
console.log('== calling assert fail');
that.callback(new Error('We should have failed'));
});
} catch (e) {
this.callback();
}
},
'gets a callback': function(err) {
assert.ok(! err);
}
}
});
suite.addBatch({
"i18n.abide middleware allows re-naming the format fn": {
topic: function(){
var middleware = i18n.abide({
format_fn_name: 'i18nFormat'
});
var that = this;
var _locals = {};
var req = {
headers: {
'accept-language': "pl,fr-FR;q=0.3,en-US;q=0.1"
},
// format from express-resource
format: function(v) {
this.formatCalled = v;
}
};
_locals.format = req.format;
middleware(req, makeResp(_locals), function() {
// The request and response objects both get
// references to i18n related variables and fn
// Example: req.lang as well as _locals.lang
[req, _locals].forEach(function(obj){
assert.ok(obj.format);
assert.equal(typeof obj.format, 'function');
// Existing format is callable and functional
obj.format('foo');
assert.ok(obj.formatCalled, 'foo');
// Our renamed i18n.format is callable and functional
assert.ok(obj.i18nFormat);
assert.equal(typeof obj.i18nFormat, 'function');
var h = obj.i18nFormat("%s %s!", ["Hello", "World"]);
assert.equal(h, 'Hello World!');
});
that.callback();
});
},
'gets a callback': function(err) {
assert.ok(! err);
}
}
});
// run or export the suite.
if (process.argv[1] === __filename) suite.run();
else suite.export(module);
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