-
Notifications
You must be signed in to change notification settings - Fork 1
/
localization.js
35 lines (34 loc) · 991 Bytes
/
localization.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
class Localization {
constructor() {
this._languageFileMap = {
'de-DE': './locale/de.json',
'en-US': './locale/en.json',
'en-GB': './locale/en.json'
};
this._languageDataMap = {};
this.locale = "de-DE";
}
setLocale(key) {
this.locale = key;
this.loadLanguage(key);
}
loadLanguage(key) {
if(key in this._languageDataMap) {
return;
}
if(!key in this._languageFileMap) {
throw new Exception("Didn't find language");
}
this._languageDataMap[key] = require(this._languageFileMap[key]);
}
translateResponse(key) {
return this._languageDataMap[this.locale].responses[key];
}
getDataElement(key) {
return this._languageDataMap[this.locale].data[key];
}
getUtterances(intent) {
return this._languageDataMap[this.locale].utterances[intent];
}
}
module.exports = new Localization();