-
Notifications
You must be signed in to change notification settings - Fork 4
/
MessageProvider.cfc
39 lines (33 loc) · 988 Bytes
/
MessageProvider.cfc
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
component accessors="true" {
property string resourceBundle;
property struct messages;
function init(resourceBundle) {
setMessages({});
loadResourceBundle(getDefaultResourceBundle());
if (structKeyExists(arguments,"resourceBundle")) {
setResourceBundle(arguments.resourceBundle);
loadResourceBundle(arguments.resourceBundle);
}
return this;
}
private function loadResourceBundle(path) {
var file = fileOpen(path);
var messages = getMessages();
while (! fileIsEOF(file)) {
var x = fileReadLine(file);
var type = listFirst(x,"=");
var message = listLast(x,"=");
messages[type] = message;
}
}
public function getMessage(type) {
var messages = getMessages();
if (structKeyExists(messages,type)) {
return messages[type];
}
return "";
}
private function getDefaultResourceBundle() {
return getDirectoryFromPath(getCurrentTemplatePath()) & "resources/DefaultMessages.properties";
}
}