i18n-abide
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -70,3 +70,3 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
// check if the option is 'key-value-json' if so the file format would be 'json' instead | ||
var file_format = options.translation_type == 'plist' ? 'plist' : 'json' | ||
var file_format = options.translation_type == 'plist' ? 'plist' : 'json'; | ||
var filename = 'messages.' + file_format; | ||
@@ -132,12 +132,10 @@ return path.resolve(path.join(__dirname, '..', '..', '..'), | ||
// Look for a lang we know about, and if found, strip it off the URL so routes | ||
// continue to work. If we don't find it (i.e., comes back "unknown") then bail. | ||
// We do this so that we don't falsely consume more of the URL than we should | ||
// and stip things that aren't actually locales we know about. | ||
var lang = bestLanguage(parseAcceptLanguage(matches[1]), | ||
options.supported_languages, | ||
options.default_lang); | ||
// If we get back the default lang, we need to be careful about stripping | ||
// the URL, since it might also mean we didn't find one we know about. | ||
// Check for the URL actually containing the default lang and allow, | ||
// otherwise bail, and don't strip URL or override header. | ||
if (lang === options.default_lang && | ||
localeFrom(matches[1]) !== options.default_lang) { | ||
"unknown"); | ||
if (lang === "unknown") { | ||
return; | ||
@@ -308,2 +306,3 @@ } | ||
var lower = supported_languages.map(function(l) { return l.toLowerCase(); }); | ||
console.log(languages, supported_languages, defaultLanguage); | ||
for(var i=0; i < languages.length; i++) { | ||
@@ -310,0 +309,0 @@ var lq = languages[i]; |
@@ -5,3 +5,3 @@ { | ||
"description": "Express/connect module for Node i18n and l10n support", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"homepage": "https://github.com/mozilla/i18n-abide", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -9,2 +9,3 @@ #!/usr/bin/env node | ||
vows = require('vows'), | ||
path = require('path'), | ||
i18n = require('../lib/i18n'); | ||
@@ -294,4 +295,98 @@ | ||
suite.addBatch({ | ||
"i18n.abide middleware correctly strips known langs from URLs": { | ||
topic: function(){ | ||
var middleware = i18n.abide({ | ||
supported_languages: [ 'en', 'fr', 'de' ], | ||
default_lang: 'en', | ||
translation_type: 'key-value-json', | ||
translation_directory: path.join(__dirname, 'locale'), | ||
locale_on_url: true | ||
}); | ||
var that = this; | ||
var _locals = {}; | ||
var req = { | ||
url: '/fr/', | ||
headers: {} | ||
}; | ||
middleware(req, makeResp(_locals), function() { | ||
assert.equal(req.url, "/"); | ||
assert.equal(req.lang, "fr"); | ||
assert.equal(req.locale, "fr"); | ||
assert.equal(_locals.lang, "fr"); | ||
assert.equal(_locals.lang_dir, "ltr"); | ||
that.callback(); | ||
}); | ||
}, | ||
'gets a callback': function(err) { | ||
assert.ok(! err); | ||
} | ||
} | ||
}); | ||
suite.addBatch({ | ||
"i18n.abide middleware correctly leaves unknown langs on URLs": { | ||
topic: function(){ | ||
var middleware = i18n.abide({ | ||
supported_languages: [ 'en', 'fr', 'de' ], | ||
default_lang: 'en', | ||
translation_type: 'key-value-json', | ||
translation_directory: path.join(__dirname, 'locale'), | ||
locale_on_url: true | ||
}); | ||
var that = this; | ||
var _locals = {}; | ||
var req = { | ||
url: '/ru/', | ||
headers: {} | ||
}; | ||
middleware(req, makeResp(_locals), function() { | ||
assert.equal(req.url, "/ru/"); | ||
assert.equal(req.lang, "en"); | ||
assert.equal(req.locale, "en"); | ||
assert.equal(_locals.lang, "en"); | ||
assert.equal(_locals.lang_dir, "ltr"); | ||
that.callback(); | ||
}); | ||
}, | ||
'gets a callback': function(err) { | ||
assert.ok(! err); | ||
} | ||
} | ||
}); | ||
suite.addBatch({ | ||
"i18n.abide middleware does the right thing with accept-language when locale_on_url is used": { | ||
topic: function(){ | ||
var middleware = i18n.abide({ | ||
supported_languages: [ 'en', 'fr', 'de' ], | ||
default_lang: 'en', | ||
translation_type: 'key-value-json', | ||
translation_directory: path.join(__dirname, 'locale'), | ||
locale_on_url: true | ||
}); | ||
var that = this; | ||
var _locals = {}; | ||
var req = { | ||
url: '/', | ||
headers: { | ||
'accept-language': 'ru;q=0.1' | ||
} | ||
}; | ||
middleware(req, makeResp(_locals), function() { | ||
assert.equal(req.lang, "en"); | ||
assert.equal(req.locale, "en"); | ||
assert.equal(_locals.lang, "en"); | ||
assert.equal(_locals.lang_dir, "ltr"); | ||
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); |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
95132
58
1209
1