Added language support

This commit is contained in:
2018-03-10 22:25:03 +11:00
parent c24c29c899
commit 370b556ed1
7 changed files with 113 additions and 15 deletions

View File

@ -10,11 +10,37 @@ class Language {
}
setLanguage(lang) {
this.langName = lang;
this.data = LANGUAGES[lang];
}
get(key) {
getLanguage() {
return this.langName;
}
get(key) {
return this.getRecursive(key.split(".")) || "Missing \"" + key + "\"";
}
getRecursive(key_array, data_obj) {
if(typeof data_obj === typeof undefined) data_obj = this.data;
if(typeof data_obj === typeof undefined) return null;
let k = key_array[0];
let o = data_obj[k];
if(typeof o === typeof undefined) return null;
//Awesome
if(key_array.length > 1) {
if(typeof o !== typeof {}) return null;
key_array.shift();
return this.getRecursive(key_array, o);
}
return o;
}
getLanguages() {
return Object.keys(LANGUAGES);
}
}

View File

@ -1,3 +1,21 @@
module.exports = {
""
"contact": {
"form": {
"title": "Contact",
"info": "Want to contact me and other lorem ipsum dolor sit amet.",
"name": {
"label": "Name",
"placeholder": "Enter your name."
},
"email": {
"label": "Email",
"placeholder": "Enter your email address.",
},
"message": {
"label": "Message",
"placeholder": "Enter your message here."
},
"submit": "Send"
}
}
}