-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
47 lines (39 loc) · 1.31 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
var Accessible = require('../../util/accessible-object'),
_ = require('underscore');
function Strings (name, root) {
Strings.superclass.call(this, root);
this.name = name;
this.base = root.base;
}
//------------------------------------------------------------------------------
// Static
//------------------------------------------------------------------------------
_.extend(Strings, {
setLocale: function (name) {
this._currentLanguage = name;
},
language: function (name) {
name = name || 'en';
return require('lib/i18n/strings/' + name + '.js');
},
get: function (path) {
return Strings.language().get(path);
},
bind: function (path) {
return Strings.language().bind(path);
}
});
//------------------------------------------------------------------------------
// Instance
//------------------------------------------------------------------------------
module.exports = Accessible.extend(Strings, {
get: function (path) {
var value = Strings.superproto.get.call(this, path),
base = this.base && require('./' + this.base);
if (typeof value === 'undefined' && base) {
value = base.get(value);
}
value = typeof value === 'undefined' ? '' : value;
return value;
}
});