-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlang.js
45 lines (33 loc) · 945 Bytes
/
lang.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
var Messages = require('./messages');
require('./lang/en');
var require_method = require;
var container = {
messages: {},
_set: function(lang, rawMessages) {
this.messages[lang] = rawMessages;
},
_setRuleMessage: function(lang, attribute, message) {
this._load(lang);
if (message === undefined) {
message = this.messages[lang].def;
}
this.messages[lang][attribute] = message;
},
_load: function(lang) {
if (!this.messages[lang]) {
try {
var rawMessages = require_method('./lang/' + lang);
this._set(lang, rawMessages);
} catch (e) {}
}
},
_get: function(lang) {
this._load(lang);
return this.messages[lang];
},
_make: function(lang) {
this._load(lang);
return new Messages(lang, this.messages[lang]);
}
};
module.exports = container;