Permalink
Browse files

Added tests. Removed callback

  • Loading branch information...
masylum committed Apr 24, 2011
1 parent fd1a502 commit 87fdf6c638b500a9afe8ba65a15c014787f16f81
Showing with 16 additions and 18 deletions.
  1. +3 −4 Readme.md
  2. +7 −11 lib/connect-i18n.js
  3. +6 −3 package.json
View
@@ -1,7 +1,6 @@
# Connect i18n middleware
-Almost inexistant middleware that checks the accept-languages
-header and adds them to the request.
+Accept-languages header parser middleware
npm install 'connect-i18n'
@@ -14,6 +13,6 @@ header and adds them to the request.
* default_locale: Sets your default locale
-## callback
+## test
-Hook to implement your own behaviour after parsing the accept-languages header.
+ make
View
@@ -1,30 +1,27 @@
-/**
- * Module dependencies.
- */
-
var queryString = require('querystring');
/**
- * Extracts locales from accept language headers
+ * Parse from Accept-language header
*
* @return {Function}
* @api public
*/
-module.exports = function i18n(options, callback) {
+module.exports = function (options) {
options = options || {};
if (!options.default_locale) {
- options.default_locale = 'en_us';
+ options.default_locale = 'en-us';
}
return function i18n(req, res, next) {
- var acceptLanguage = req.headers['accept-language'],
+ var accept_language = req.headers['accept-language'],
+ tokens = [],
locales = [];
- if (acceptLanguage) {
- acceptLanguage.split(',').forEach(function (lang) {
+ if (accept_language) {
+ accept_language.split(',').forEach(function (lang) {
locales.push(lang.split(';', 1)[0].toLowerCase());
});
@@ -33,7 +30,6 @@ module.exports = function i18n(options, callback) {
req.locales = [options.default_locale];
}
- callback(req.locales);
next();
};
};
View
@@ -1,9 +1,12 @@
{
"name": "connect-i18n",
- "description": "Add locales to your request",
- "version": "0.0.1",
+ "description": "Accept-language header parser middleware",
+ "version": "0.2.0",
"author": "Pau Ramon <masylum@gmail.com>",
"main": "./lib/connect-i18n",
- "engines": { "node": ">= 0.1.98" }
+ "devDependencies": {
+ "testosterone": ">= 1.2.0"
+ }
+ "engines": { "node": ">= 0.4.0" }
}

0 comments on commit 87fdf6c

Please sign in to comment.