-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
65 lines (47 loc) · 1.25 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module.exports = function(sails) {
/**
* Module dependencies.
*/
var _ = require('@sailshq/lodash');
// Declare a private var to hold the instantiated i18n module.
var i18n;
/**
* Expose hook definition
*/
return {
defaults: {
// i18n
i18n: {
locales: ['en', 'es', 'fr', 'de'],
defaultLocale: 'en',
localesDirectory: '/config/locales'
}
},
routes: {
before: {
'all /*': function addLocalizationMethod (req, res, next) {
i18n.init(req, res, function() {
res.locals.i18n = res.i18n = res.__;
next();
});
}
}
},
initialize: function(cb) {
i18n = require('i18n');
i18n.configure(_.defaults(sails.config.i18n, {
cookie: null,
directory: sails.config.appPath + sails.config.i18n.localesDirectory,
updateFiles: false,
extension: '.json',
logDebugFn: function(log){sails.log.verbose('i18n:', log);},
logWarnFn: function(log){sails.log.warn('i18n:', log);},
logErrorFn: function(log){sails.log.error('i18n:', log);},
}));
// Expose global access to locale strings
sails.__ = i18n.__;
// Finally
cb();
}
};
};