Skip to content

Commit

Permalink
initial work with i18n support
Browse files Browse the repository at this point in the history
  • Loading branch information
particlebanana committed Jul 18, 2013
1 parent c2c74dd commit 882a15b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
16 changes: 16 additions & 0 deletions bin/boilerplates/config/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports.i18n = {

// Which locales are supported?
locales: ['en-US'],

// What is the default locale?
defaultLocale: 'en-US',

// Where are your locale translations located?
localesDirectory: 'config/locales',

// Which format are your locales in?
// available: [po, plist, json]
translationType: 'json'

};
9 changes: 9 additions & 0 deletions lib/configuration/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module.exports = function (sails) {
pubsub : require('../hooks/pubsub'),
policies : require('../hooks/policies'),
csrf : require('../hooks/csrf'),
i18n : require('../hooks/i18n'),
http : require('../hooks/http')
},

Expand Down Expand Up @@ -110,6 +111,14 @@ module.exports = function (sails) {

},

// i18n
i18n: {
locales: ['en-US'],
defaultLocale: 'en-US',
localesDirectory: 'config/locales',
translationType: 'json'
},


// CSRF middleware protection, all non-GET requests must send '_csrf' parmeter
// _csrf is a parameter for views, and is also available via GET at /csrfToken
Expand Down
39 changes: 39 additions & 0 deletions lib/hooks/i18n/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = function(sails) {

/**
* Module dependencies.
*/

var _ = require('lodash'),
Hook = require('../../index'),
i18n = require('i18n-abide');

var i18n_middleware = i18n.abide({
supported_languages: sails.config.i18n.locales,
default_lang: sails.config.i18n.defaultLocale,
translation_directory: sails.config.appPath + sails.config.i18n.localesDirectory,
translation_type: sails.config.i18n.translationType
});


/**
* Expose hook definition
*/

return {

routes: {

before: {

'/*': i18n_middleware

}
},

// Always ready-- doesn't need to do anything asynchronous
// (err sort of- but it's fine)
ready: true

};
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"grunt-contrib-cssmin": "0.6.1",
"grunt-contrib-less": "0.5.2",
"ejs": "0.8.4",
"ejs-locals": "1.0.2"
"ejs-locals": "1.0.2",
"i18n-abide": "0.0.10"
},
"devDependencies": {
"mocha": "*",
Expand Down

0 comments on commit 882a15b

Please sign in to comment.